13

我更改了我朋友正在同时工作的文件。我做了一些更改,现在我想推它,但它说我应该先拉。当我git pull,它说:

错误:您对以下文件的本地更改将被合并覆盖:请在合并之前提交您的更改或存储它们。
中止

如何合并文件?如果我这样做,我朋友的文件会完全改变吗?我确信他添加了一些东西,我也添加了我的东西。我们的变更将如何处理?

4

2 回答 2

21

一种方法是先提交该文件,然后再拉取。

git add filename
git commit 
//enter your commit message and save 
git pull 

另一种方法是存储您的更改然后拉取。然后应用存储。

git stash
git pull
git stash apply stash@{0}
于 2013-08-28T17:07:27.133 回答
2

Do git commit and then git pull. It fetch your friend changes at first and then merge your changes, nothing will be lost.

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.

于 2013-08-28T17:01:39.603 回答