24

If the following is a list of commits on a branch:

A - B - C - D

How can I combine commits A and C into (AC)?

(AC) - B - D
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133

2 Answers2

39

First do git rebase -i aaaaaa^ and then your text editor will show up looking like this:

pick aaaaaa
pick bbbbbb
pick cccccc
pick dddddd

Change it so that it looks like

pick aaaaaa
squash cccccc
pick bbbbbb
pick dddddd

and close it and git does the rest.

http://git-scm.com/docs/git-rebase

JotaDeAA
  • 35
  • 6
Tyler
  • 21,762
  • 11
  • 61
  • 90
  • 6
    And the obligatory warning: don't do this if you've already pushed any of this work. – Cascabel Mar 19 '11 at 14:21
  • 4
    Also, to clarify, `A` in the first command is the SHA1 of commit `A` (it may be abbreviated), and `aaaaaa` and friends in the editor are abbreviated SHA1s of the four commits. – Cascabel Mar 19 '11 at 14:22
0
git rebase -i A^

edit them so that C is after A. Change the pick to f (fixup) and save.

Dustin
  • 89,080
  • 21
  • 111
  • 133