在这种情况下,为什么我的本地更改会被checkout覆盖? [英] Why would my local changes in Git be overwritten by checkout in this circumstance?

查看:797
本文介绍了在这种情况下,为什么我的本地更改会被checkout覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个分支A,并从那里分支B.我对A进行了一系列更改,然后检出B并执行 git pull 。现在我对B做出了改变,但是意识到它应该在A中。如果我现在尝试 git checkout A ,我会得到您的本地更改为以下文件将会被checkout覆盖到我触摸的文件中。

为什么如果我只是在B中执行git pull而没有触及该文件,我的更改会被覆盖自从?

解决方案

你得到这个消息的原因是底层文件(在未提交的修改之前)是不同的在分支A和分支B之间。如果文件相同,Git会在切换到分支A后切换分支并保持相同的未提交的修改。



一(b分支)$ git存储
git checkout A(分支B)

  
git stash pop

如果有冲突的更改,您可能需要解决冲突这点。如果有变化但不冲突,那么这将会成功。


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?

解决方案

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.

这篇关于在这种情况下,为什么我的本地更改会被checkout覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆