by now, I know that there is a nice way how to combine commits and change the commit message by using 'git rebase --interactive'
Having the following situation:
$ git rebase --interactive HEAD^^^^
pick 5b7c140 commitA
pick 40ffd7c commitB
pick 5e7647d commitC
pick 78bea2d commitD
Rebase [...]
Is there also a possibility to handle the following requirements:
Combining commitA and commitC and commitB and commitD to new commits cAC and cBD?
In the list of branches, select the branch that has the commits that you want to squash. Click History. Select the commits to squash and drop them on the commit you want to combine them with. You can select one commit or select multiple commits using Command or Shift .
But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .
It is possible - you can also rearrange the order of the commits with interactive rebase:
pick 5b7c140 commitA
squash 5e7647d commitC
pick 40ffd7c commitB
squash 78bea2d commitD
or
pick 5b7c140 commitA
fixup 5e7647d commitC
pick 40ffd7c commitB
fixup 78bea2d commitD
The difference between the two is that squash
allows you to edit the commit message for the new commits, whereas fixup
just throws away the second commit message leaving the preceeding pick
commit message in place for the combined commit. (If your editor launches quickly enough, then having the habit of just choosing squash
gives you a nice opportunity to review the commit message even if you think you would probably not need to use parts of the message of the fixup
commit.)
There is a possibility of rebase conflict, if your commitB
and commitC
change a same part of a file. Often these can be easily enough sorted out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With