0

E.g. I have a feature branch based on master with 1 new commit with 2 added files.

commit hash1
A test.html
A test.png

Now I want to rebase this feature branch on master to get the latest code. Since I started working on feature branch 1 new commit in master was added.

commit hash2
A test.html

When I'm executing the git rebase master I got this output.

First, rewinding head to replay your work on top of it...
Applying: Initial commit.
Using index info to reconstruct a base tree...
M   test.html
Falling back to patching base and 3-way merge...
error: The following untracked working tree files would be overwritten by merge:
    test.html
Please move or remove them before you can merge.
Aborting
Failed to merge in the changes.
Patch failed at 0001 Initial commit. 
The copy of the patch that failed is found in:
   /<path>/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

As the result changes from feature completely negated, test.html is the version from master and the test.png was not added at all.

How to resolve this situation?

Vladimir Tsyupko
  • 163
  • 2
  • 17
  • "test.png was not added at all." it will be added only when the current error is resolved and `git rebase --continue` is done. – VonC Apr 18 '16 at 07:25

2 Answers2

0

As shown in the message, a merge conflict occurred, just solve the conflict manually, and run git rebase --continue

gzh
  • 3,507
  • 2
  • 19
  • 23
  • The matter of fact there's no conflict. I don't get the <<<<>>>>>hash parts in the `test.html` file, so there's no merge conflict. – Vladimir Tsyupko Apr 18 '16 at 09:35
  • @VladimirTsyupko when add a new file, git will create a new node for this new file. In your case, git detect you want to added new node with an existing file pathname, so it judge a conflict occurred. This conflict is about file node other than file content. – gzh Apr 18 '16 at 10:31
0

Since the same file was modified on both master and your local branch, Git is not able to merge them automatically. You will have to resolve the conflicts on your own, most modern IDEs have ways to do it, else you can look for 3 way diff with kdiff or other tools.

Once you have resolved the conflicts, you will have to tell git to continue. git rebase --continue

As to why git did not add the .png file, from Git manual you can see how rebase works:

It works by going to the common ancestor of the two branches (the one you’re on and the one you’re rebasing onto), getting the diff introduced by each commit of the branch you’re on, saving those diffs to temporary files, resetting the current branch to the same commit as the branch you are rebasing onto, and finally applying each change in turn.

Since git could not successfully apply changes to your feature branch, it paused processing for you to take action.

Community
  • 1
  • 1
dubes
  • 5,324
  • 3
  • 34
  • 47