简体   繁体   中英

Git: local branch changes not applied when rebasing on master

Eg 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?

如消息中所示,发生了合并冲突,只需手动解决冲突,然后运行git rebase --continue

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM