Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

during git rebase: same file keeps conflicting

Tags:

git

git-rebase

I checked out a branch called 'topic'. I am still working on topic, but I want to include changes that are now in master branch. So I did this:

$ git checkout topic
$ git rebase master

After that, there were merge conflicts for file xyz.txt. So I modified file to be what I wanted, git add it, and did git rebase --continue.

But immediatly, the same file had merge conflicts. I fixed the file again and this time had to do git reabase --skip to continue.

But yet again the same file has the exact same merge conflicts. How is this happening?

EDIT:

Previously, I had been merging master into topic branch to accomplish this purpose. Then I just learned of rebase. So I'm guessing that has something to do with it.


Here is the state of git right now right before the third commit

$ git status
# Not currently on any branch.
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      xyz.java
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git ls-files -u
100644 cbf74a88604dd4ee0afe89d7aac1d179ce75e92c 1       xyz.java
100644 52841c2b4b6cc055251d533d5b83441d1329b412 2       xyz.java
100644 c45e7c6b979ec1e20b7dd70b38698193ea235abd 3       xyz.java

$ git log --graph --pretty=format:%d HEAD master topic
*  (HEAD)
*
*  (master)
*
*
*
*
*
*
*
*
| *  (topic)
| *
| |\
| |/
|/|
* |
| *
| *
| |\
| |/
|/|
* |
| *
| *
| *
| *
| *
| |\
| |/
|/|
* |
| *
| *
| *
| *
| *
| *
| *
| |\
| |/
|/|
* |
* |
* |
|\ \
| * |
* | |
|/ /
| *
| *
| |\
| |/
|/|
* |
| *
| *
| *
| *
| *
| *
| *
| *
| *
| |\
| |/
|/|
* |
| *
| |\
| |/
|/|
* |
| *
| *
| *
| *
|/
*
*
like image 511
Alexander Bird Avatar asked Jan 14 '13 15:01

Alexander Bird


1 Answers

Try git rebase --interactive to validate how Git will rebase the history. There will be a list of commits that will be applied in the given order ontop of your base commit, i.e. master:

Example:

pick 12345678 # This will be the first commit of your rebased topic branch
pick deadbeef
pick ffffffff
pick 01010101 # This will be HEAD after the successful rebase

Sometimes, Git doesn't know if a commit is really new in a branch or just an existing commit (from master) with different ancestors. You can skip commits by removing them from the text file.

If this doesn't solve your conflicts immediately, there's a real conflict between the two branches. Be sure to merge the file(s) and stage them using git add. Afterwards be sure to use git rebase --continue to move on. Don't use git rebase --skip if you don't know exactly that it's useful here. (--skip will ignore the current, conflicting commit and try to apply the next commit, which might result in further inscrutable conflicts later on).

like image 159
Koraktor Avatar answered Sep 16 '22 14:09

Koraktor