|
|
|
|
|
by 000ooo000
720 days ago
|
|
> is it possible not to lose the commit description when trying to split a commit? There's 2 cases: 1) extract changes into a commit that comes before the original commit, and 2) extract changes into a commit that comes after the original commit. In both, instead of editing the commit you want to split, `break` before that commit, and then use `git checkout <hash_of_commit_to_edit> <path_to_files_of_interest>` to pull the changes of interest out into an new, earlier commit. `git checkout -p` is worth a look here. Alternatively if the changes are simple enough, you could use exec instead of break before the target commit. For 1) you can commit those extracted changes with a new message and then `git rebase --continue`. The original commit will then lack the extracted changes, and have the original commit message. If you did want to adjust it, reword that commit. e.g. pick c62dfe67 1
pick 63dcd748 2
exec git checkout eea68bb8 three.txt && git commit -m "3"
reword eea68bb8 3+4
For 2) reference the target commit's message as the new, earlier commit's message. Keep in mind that the git invocation in this exec here still supports git aliases so if this was something you do often, you could create an alias for retrieving the next commit message and that last part of the exec could just be `.. && git getnextcommitmessage`e.g. pick c62dfe67 1
pick 63dcd748 2
exec git checkout eea68bb8 four.txt && git commit -m "$(git log -1 eea68bb8 --format="%B")"
reword eea68bb8 3+4
|
|