Search code examples
gitgit-rebasegit-squash

How does git handle a squash commit after a fixup commit?


I'm working with a branch with a fairly large number of commits and would like to do an interactive rebase to condense it into fewer commits before merging to master. In order to avoid weird conflicts, I'm trying to maintain a certain order to the commits where possible, but sometimes need a commit message to be maintained in a long string of fixups. In other words, I have something like:

pick abc123 commit A
f jkl567 commit B
f def345 commit C
s mno789 commit D
f xyz901 commit E

Will the message from the squash commit still be preserved on the first picked commit or will it do something like squash 'commit D' into commit C and then end up dropping the commit message when commit C gets "fixed up" into commit B and then into commit A?


Solution

  • Git is doing it in order one by one so it will:

    1. Fix up with B, keeping commit message from A
    2. Fix up the new commit with C, keeping commit message from A
    3. Squash with D, asking to edit message from A+D
    4. Fix up with E, so keeping the version you saved in 3.)