简体   繁体   中英

Unexpected error when rebasing with git from a branch to another branch, some files seems to be modified during the process

I have unexpected errors when trying rebasing a git branch on another. Given two git branch A and B, and base_commit the common commit for these two branches in the history.

A is ahead of base_commit by 2 commits and B is ahead of base_commit by 3 commits for example (the values are not important, just to say that the two branches are "close").

When I try to rebase A on B, it appends sometimes an error :

error: Your local changes to the following files would be overwritten by merge:
[...]
Please, commit your changes or stash them before you can merge.
Aborting
Failed to merge in the changes.
Patch failed at 0004 Passage de ZIM sous forme d'une bibliothèque

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

But there is no change in the index (git status gives nothing)

A solution is to abort and retry and sometimes it works. Doing a git gc can help but not always...

I am on MacOS X and the code is made with XCode, I have no antivirus and even when XCode and SourceTree are over the problem appears.

Any help would be very appreciated. Thank you.

Let's say branches A and B , standing on A , file f was modified (and not checked into A ), while B contains another version. If I try to rebase B onto A , the local changes for f are lost. Solution: Commit the changes to f , or stash them away for later, or perhaps discard them by git checkout f .

That is what the message says, in a nutshell.

If you "tried again until it worked", you probably lost changes like the above.

Morals of the story: If you want to do any more complex operation with git (like pulling from upstream, rebasing, changing last commit, ...) make sure everything is tidy. Ie, git status says it is clean, and hopefully no untracked files.

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