Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: interactive rebase lists incorrect (too many) commits

Tags:

When I run git rebase -i HEAD~2, it lists 11 commits instead of 2. Why?

What I've done prior to this was:

  1. Checked out upstream/branchA
  2. Rebased my new local copy of branchA with master
  3. Tried to push my local branchA back to upstream
    • Git complained that the branches were out of sync, and to first pull in upstream
  4. Pulled upstream/branchA into local branchA
  5. Pushed local branchA to upstream/branchA (success)
like image 534
Jakob Jingleheimer Avatar asked Oct 15 '14 00:10

Jakob Jingleheimer


People also ask

Why is git rebase showing too many commits?

When you find "extra" commits like this that means there's a merge commit (a 2nd parent) in the mix and you're including the commits on both sides of the merge.

What git rebase master does?

The Rebase Option This moves the entire feature branch to begin on the tip of the main branch, effectively incorporating all of the new commits in main . But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.


1 Answers

It depends on how your git tree looks like. A "merge" commit for instance can have two or more parents. Depending on this, your commit can have multiple grandparents.

You probably need to rebase with

git rebase -i HEAD^1^2 git rebase -i HEAD^2^1 git rebase -i HEAD^2^2 

(one of these three).

See here for more details about git's relative commit notation.

like image 175
Willem Van Onsem Avatar answered Dec 12 '22 16:12

Willem Van Onsem