Git pull 自身中止,本地文件更改将被合并覆盖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18486570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git pull aborts itself, local file changes will be overwritten by merge
提问by Sasha_8
I have changed a file that my friend is working at the same time. I did some changes and now I want to push it but it says I should pull first. When I git pull
, it says:
我已经更改了我朋友正在同时工作的文件。我做了一些改变,现在我想推动它,但它说我应该先拉。当 I 时git pull
,它说:
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
错误:您对以下文件的本地更改将被合并覆盖:请在合并之前提交您的更改或隐藏它们。
中止
How can I merge the file? If I do it would the file from my friend completely change? I am sure he has added some stuff and I have added my stuff. How will our changes be handled?
如何合并文件?如果我这样做,我朋友的文件会完全改变吗?我确定他添加了一些东西,而我也添加了我的东西。我们的变更将如何处理?
回答by nyzm
One approach is to commit that file first then pull.
一种方法是先提交该文件,然后再拉取。
git add filename
git commit
//enter your commit message and save
git pull
Another approach is stash your changes then pull. Then apply stash.
另一种方法是隐藏您的更改然后拉取。然后申请藏匿。
git stash
git pull
git stash apply stash@{0}
回答by Leonid Shvechikov
Do git commit
and then git pull
. It fetch your friend changes at first and then merge your changes, nothing will be lost.
做git commit
然后git pull
。它首先获取您朋友的更改,然后合并您的更改,不会丢失任何内容。
Conflicts between your changes will be represented such way:
您的更改之间的冲突将以这种方式表示:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
Or you could use some interactive merge tool.
或者您可以使用一些交互式合并工具。