Why would my local changes in Git be overwritten by checkout in this circumstance?

无人久伴 提交于 2019-12-22 06:44:30

问题


Say I have a branch A, and from that I branch B. I make a bunch of changes on A, then checkout B and do a git pull. Now I make a change on B but realize that it should've been in A. If I now try to git checkout A, I get "Your local changes to the following files would be overwritten by checkout" to the file I touched.

Why would my change be overwritten if I just did a git pull in B and haven't touched that file in A since?


回答1:


The reason you get that message is that the underlying file (before your uncommitted modifications) is different between branch A and branch B. If the files were the same, Git would switch branches and keep the same uncommitted modifications after switching to branch A.

One way to bring these changes across is to stash them:

(on branch B)$ git stash
git checkout A
git stash pop

If there are conflicting changes, you may have to resolve the conflict at this point. If there are changes but they don't conflict, then this will succeed.



来源:https://stackoverflow.com/questions/12044716/why-would-my-local-changes-in-git-be-overwritten-by-checkout-in-this-circumstanc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!