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.

3
  • 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? Commented Jun 20, 2015 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? Commented Jun 20, 2015 at 20:55
  • I'd rather have bad commits than a fully rebased revision history... I value truth over a clean commit log Commented Jun 22, 2015 at 7:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I should do this while I am on the Feature branch right?
yes, when you're in the feature branch in the last diagram of your question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.