0

I was working in branch "Feature".
So my git tree was:

                  master
A<--B<--C<--D<--F<--G
            |<--E
                Feature  

I wanted to get all the latest of master while working on Feature branch so I did:

git checkout Feature  
git rebase master  

During the rebase I got a merge conflict in one file and during resolving the conflict manually I did a mistake which I realized later and not before running git rebase --continue
So I ended up with a tree as follows:

                 master      
A<--B<--C<--D<--F<--G<--E  
                       Feature

Then I realized about my mistake that actually broke the build in E.
I corrected my mistake (not commited yet) and continued my work but I don't want to have 2 commits in Feature that will end up in master and the one of the commits is a bad commit.
Also I would like to end up with a single commit in master branch of my work in Feature.
So if I have:

                 master      
A<--B<--C<--D<--F<--G<--E<--H  
                           Feature   

How can I combine E and H into one commit so that when I do:

git checkout master  
git rebase feature   

I have only 1 commit in my master? Note: The branch Feature is local and not pushed in case it matters.

Jim
  • 18,826
  • 34
  • 135
  • 254
  • Perhaps not relevant, but I have to ask: **Why?** The hole point of VCS is that you can _see_ who committed what, when and why. If you systematically rewrite your history, what's the point? Why not use tarballs to manage the source? So what if there are 2 or more commits visible, that's because there were several commits... why would you want to hide that? – Elias Van Ootegem Jun 20 '15 at 16:57
  • @EliasVanOotegem:What is the point of having a commit that is a bad commit in history because of a manual/editing error? – Jim Jun 20 '15 at 20:55
  • I'd rather have bad commits than a fully rebased revision history... I value truth over a clean commit log – Elias Van Ootegem Jun 22 '15 at 07:27

1 Answers1

4

You can use interactive rebase to combine two commits. You need to use the squash option on the second one.

Start with:

git rebase -i HEAD~2

in the editor, you will see 2 lines in this order:

pick E's SHA-1
pick H's SHA-1

replace it with

pick E's SHA-1
squash H's SHA-1

Then close the editor. Git will pick E, then combine H to it.

You will be prompted for a new, combined commit message. Close that editor when finished and the rebase will finish by itself.

Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29