This situation is handled by interactive rebase . The standard warning that there is no overwriting of the history that was clicked applies. There is a worthy explanation in the Git book , but I personally believe that the rebase -i interface should be exactly upside down.
Start rebase by naming the parent of the earliest commit you need to change:
$ git rebase -i 94126f7^
The editor pops up, listing commits in chronological order forward (so you need to turn your head upside down). It lists all the commits from HEAD to the child of the commit name, so you called it the parent:
pick 94126f7 Added abbreviations chapter pick 74069a1 Changed some headings in the introduction pick 652b4c2 Added longtable package for abbreviations pick 326f35d Small editing in ASR chapter
What you want to do is squash commit 652b4c2 to 94126f7, so you change its command to "squash" and move it right after the last one:
pick 94126f7 Added abbreviations chapter squash 652b4c2 Added longtable package for abbreviations pick 74069a1 Changed some headings in the introduction pick 326f35d Small editing in ASR chapter
Save and exit; the next editor that appears will be for the combined commit message. You can change it however you want, then when you exit it, it will finish rebase.
Conflicts on reboot can be annoying (some fixes just wonβt commute), and merging can be especially ugly, but there will be no problems reordering files.
source share