解决Git合并冲突 [英] Resolving Git merge conflicts
问题描述
错误:对以下文件的本地更改将被合并覆盖:
public_html / sites / file
public_html / sites / file1.txt
public_html / sites / file2.txt
请在提交更改或隐藏它们之前进行合并。
正在取消
我已经在网上阅读了很多主题,并且有几个不同的选项建议。运行一种方法:
git stash
git pull
git stash pop
code>
我想我理解存储的基本原理。我的问题是,这是一个很好的解决方案,我可以用这种方法解决任何问题吗?我对Web开发有一个合理的理解,但是我是一个相当基础的Git用户,在这一点上我没有很多能力摆脱困境。
git stash apply
,不过 apply
。)
您是否有理由在合并之前不想提交这些更改?通常这是正确的做法。
另一个选择是:
git存储
git checkout -b newwork
git stash apply
git commit ...
创建一个新的分支,它可以让你的主人在没有冲突的情况下保持最新状态(再次检出主人,然后拉或取+合并)。然后你可以把你的分支合并回来(同时仍然在master上) git merge newwork
。您可以解决master上的冲突,同时仍然保留newwork上的工作而不会造成任何冲突。如果你担心冲突真的使事情变得更糟,那么这样会更安全些,但通常情况下,冲突只是流程的一部分,所以不要太担心。
A Git repository has been cloned on several developers' local machines. Some changes have been made to the code in the repository. We're now getting the error:
error: Your local changes to the following files would be overwritten by merge:
public_html/sites/file
public_html/sites/file1.txt
public_html/sites/file2.txt
Please, commit your changes or stash them before you can merge.
Aborting
I've read quite a few threads online, and several different options have been suggested. One approach was run:
git stash
git pull
git stash pop
I think I understand the basic principle of stashing. My question is, is this a good solution, and could I run into any issues using this approach? I have a reasonable understanding of web development in general, but I'm a fairly basic Git users and wouldn't have a lot of ability to get myself out of trouble at this point.
git stash
is perfectly legitimate, though as Greg said, for some reason fixing the conflicts can get strange. But they are still fixable, you won't actually fubar anything. The command as I know to re-apply the stash is git stash apply
, though pop
may be an alternative that I'm not aware of (or it could do something different, I don't know, so you probably want to use apply
.)
Is there a reason you don't want to commit those changes before merging? Generally that's the right thing to do.
Another option is:
git stash
git checkout -b newwork
git stash apply
git commit ...
This creates a new branch, which will allow you to get your master up to date without conflicts, (checkout master again, then pull or fetch + merge). Then you can merge your branch back with (while still on master) git merge newwork
. You can resolve the conflicts on master, while still retaining the work on newwork without any conflicts. This is a bit safer if you are worried about conflicts really screwing things up, but generally, conflicts are just part of the process, so don't worry too much about them.
这篇关于解决Git合并冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!