GIT: Why do I have to resolve merge conflicts twice when using rebase?

I really like the git pull --rebase , but when used in conjunction with a merge conflict, I end up resolving my conflicts twice. I tried using git pull --rebase=preserve , which should make it take merge into account as well.

Try a look at the following example:

 # do a new clone "a" $ mkdir origin && cd origin && git init --bare --shared && cd .. $ git clone ./origin a && cd a # Add, commit, push a (master) $ echo "foo" > foo && git add foo && git commit -m "foo" a (master) $ git push origin master # Create branch "b" a (master) $ git branch b # change foo and push a (master) $ echo "// eof " >> foo && git ci -am "eof - master" a (master) $ git push origin master # checkout branch "b", change and push a (master) $ git checkout b a (b) $ echo "// EOF " >> foo && git ci -am "EOF b" && git push origin b # back to master a (b) $ git checkout master # merge a (master) $ git merge b # conflict as expected a (master) $ git diff diff --cc foo index e10b853,1d3cc50..0000000 --- a/foo +++ b/foo @@@ -1,2 -1,2 +1,6 @@@ foo ++<<<<<<< HEAD +// eof ++======= + // EOF ++>>>>>>> b # Now, resolve the conflict a (master|MERGING) $ echo "foo" > foo && echo "// eof" >> foo && git add foo a (master|MERGING) $ git commit # In the mean while somewhere else. ############################################ a (master) $ cd .. && git clone ./origin other && cd other/ other (master) $ echo "bar" > bar && git add bar && git ci -am "bar" && git push # OK # Back to us ################################################################### other (master) $ cd ../a a (master) $ git push # will fail... # I now do a rebase preserve as I want to rebase my merge commit to the top of master a (master) $ git pull --rebase=preserve # This command does not do a very good job... a (master|REBASE-i 1/1) $ git diff diff --cc foo index e10b853,1d3cc50..0000000 --- a/foo +++ b/foo @@@ -1,2 -1,2 +1,6 @@@ foo ++<<<<<<< HEAD +// eof ++======= + // EOF ++>>>>>>> 3cd5d3ac5b870c613233f0a9f1a81df5691ccc7c 

If I replaced git pull --rebase=preserve with git pull --no-rebase , then it works as expected (I only need to resolve conflicts once), but then I have to look at all these merge commits in my log.

How can I make a git "rebase" merge and conflict solution to fit on top on a new remote HEAD?

+8
git git-branch
source share
2 answers

I found that the Git "rerere" function solved my problem.

Documented in: git rerere --help or http://git-scm.com/docs/git-rerere

Adding this to my .gitconfig

 [rerere] enabled = true 

Solved my problem.

+5
source share

Rebase basically just takes the commit between HEAD and base and sequentially applies them to the base . This means that if you had some mergers between them, they are lost and you will have to resolve conflicts again. Illustration:

Say you have a tree:

 A--B---M \ / `-C' 

M is the merging of conflicting changes between B and C , and this is your HEAD . Now, if you run git rebase A , then git will try to create the following tree:

 ABC 

But when trying to apply C to B he is faced with a conflict. Ignoring the M merge, he should ask you for the user to allow it.

At this point, you can simply check the files in question from the version of M in which they are already merged: git checkout M -- file/with/conflict , but I do not know how to do this automatically (for example, the redirection option) .

Honestly, I really don’t understand that people don’t like merging, I personally find them useful, but if you want, you can omit them in the log using --no-merges

0
source share

All Articles