2

I had this

-A-B-C-D-

and

-A-E-F-G-

I made merge and this is what I have now

-A-B-C-D-------H-I-
  \           /
   ------E-F-G

How do I get this?

-A-B-C-D-J-

I need to combine E,F,G,H,I into one new commit.

Sorry for stupid question. I am reading man, but can't figure it out.

2 Ikke: Yes. H is a merge commit. 2 Shahbaz: I need it because the code on commit-E is not buildable (not my mistake =)) and commit-G fixes it.

xXx_CodeMonkey_xXx
  • 800
  • 1
  • 7
  • 14
  • Is H anything more than a merge commit? – Ikke Dec 13 '11 at 15:31
  • 1
    Not helping with giving you an answer, but why do you really want to have less commits? It just makes it harder for you to undo undesired changes. If you write good commit messages, more commits should in fact be even more desirable – Shahbaz Dec 13 '11 at 15:41
  • 1
    @Shahbaz: Or maybe these are tiny incremental commits (which can be very good practice) which really should be combined before publishing! – Cascabel Dec 13 '11 at 17:31

3 Answers3

2

This is by far the quickest method:

 # make sure you're on the branch that's at commit I
 git reset --soft <commit-D>
 git commit

reset --soft resets the current branch to point to the given commit, but leaves the work tree and index (staging area) as they were, so that when you commit, you're committing all the content that was there at I, in a single commit with D as parent.

(You could accomplish this with other tools, but in this case this is all you need!)

Cascabel
  • 479,068
  • 72
  • 370
  • 318
0

What you need is squashing commits have a read at this: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

Wissam Youssef
  • 800
  • 1
  • 10
  • 20
0

A merge --squash should be enough to get your expected result.

 git checkout branch_of_D
 git merge --squash branch_of_G

See "In git, what is the difference between merge --squash and rebase?".
For example of using merge --squash, see "How to use GIT merge --squash?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That won't get you H and I in there - you'd have to squash-merge that branch, then interactive rebase squash the two squash merge commits together. – Cascabel Dec 13 '11 at 17:30