Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git is stating a branch is not merged after rebasing - why?

Tags:

git

git-svn

I'm using git-svn to manage my bugfix branches, but it tells me that I have unmerged changes, even though if I review the SVN repo directly, I can see they have been committed too. It's like the rebase of the bug fix is not setting the branch as merged.

What am I doing wrong, here?

git checkout -b fix_bug_1234

git add .
git commit -m "first change"
git add .
git commit -m "second change"

git rebase -i HEAD~2 // squash the two changes together

git svn rebase // fetch any changes from svn

git checkout master
git rebase fix_bug_1234
git svn dcommit

git branch -d fix_bug_1234
error: The branch 'fix_bug_1234' is not fully merged.
like image 205
Thomas R Avatar asked Mar 23 '11 22:03

Thomas R


People also ask

How do I rebase a merged branch?

If you are certain this is the direction you want to take your history, you should start by checking out the master branch and interactively rebasing it ( git rebase -i ) onto the commit where feature was cut from (in your case, [M2] ).

Does rebasing merge?

Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

What happens when I rebase a branch?

From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.

Is rebasing a replacement for merging?

While merging is definitely the easiest and most common way to integrate changes, it's not the only one: "Rebase" is an alternative means of integration.


2 Answers

The reason for that is that git rebase changes the commit objects. So while the actual content (or diff) is the same with those rebased commits, they are referring to a different parent, and as such are different.

That way git branch -d cannot verify that the changes of those commits are included in some other commits. You need to use git branch -D (uppercase D) to force the deletion then.

On a side note: git svn dcommit has the same effect as rebasing. As dcommit pushes the commits to the SVN server, it afterwards gets the commits from the SVN server again. So you end up with different objects than the ones you pushed. Although they may be identical in content (unless you had conflicts), they still differ (main reason is that git svn adds a line to the commit message stating the SVN version the commit belongs to).

like image 117
poke Avatar answered Sep 18 '22 13:09

poke


Here is how I do this sort of thing, and it works. The answer from user poke explains why the git rebase is not doing what you want it to.

git rebase -i HEAD~2 // squash the two changes together

git svn rebase // fetch any changes from svn
git svn dcommit  // you can commit to SVN from any branch

git checkout master
git svn rebase
git branch -d fix_bug_1234
like image 22
Spike Gronim Avatar answered Sep 21 '22 13:09

Spike Gronim