我使用了git pull并发生了合并冲突:
unmerged: some_file.txt
You are in the middle of a conflicted merge.
如何放弃对文件所做的更改,只保留已提取的更改?
我使用了git pull并发生了合并冲突:
unmerged: some_file.txt
You are in the middle of a conflicted merge.
如何放弃对文件所做的更改,只保留已提取的更改?
当前回答
由于您的拉动不成功,那么HEAD(而不是HEAD^)是分支上最后一个“有效”提交:
git reset --hard HEAD
你想要的另一件事是让他们的改变凌驾于你的改变之上。
旧版本的git允许您使用“他们的”合并策略:
git pull --strategy=theirs remote_branch
但正如Junio Hamano(Git维护者)在这条消息中所解释的那样,这条消息已经被删除。如链接中所述,您可以这样做:
git fetch origin
git reset --hard origin
其他回答
由于您的拉动不成功,那么HEAD(而不是HEAD^)是分支上最后一个“有效”提交:
git reset --hard HEAD
你想要的另一件事是让他们的改变凌驾于你的改变之上。
旧版本的git允许您使用“他们的”合并策略:
git pull --strategy=theirs remote_branch
但正如Junio Hamano(Git维护者)在这条消息中所解释的那样,这条消息已经被删除。如链接中所述,您可以这样做:
git fetch origin
git reset --hard origin
git merge --abort
中止当前冲突解决过程,并尝试重建合并前状态。如果合并时存在未提交的工作树更改started,gitmerge--在某些情况下中止将无法重建这些变化。因此,建议始终在运行gitmerge之前提交或隐藏更改。git merge--abort等效于git reset--mergeMERGE_HEAD存在。
http://www.git-scm.com/docs/git-merge
为了避免陷入这种麻烦,可以扩展git合并-中止方法,并在合并之前创建一个单独的测试分支。
案例:你有一个主题分支,它没有被合并,因为你分心了/有些事情发生了/你知道,但它已经准备好了。
现在可以将其合并到master中吗?
在测试分支中工作以估计/找到解决方案,然后放弃测试分支并在主题分支中应用解决方案。
# Checkout the topic branch
git checkout topic-branch-1
# Create a _test_ branch on top of this
git checkout -b test
# Attempt to merge master
git merge master
# If it fails you can abandon the merge
git merge --abort
git checkout -
git branch -D test # we don't care about this branch really...
努力解决冲突。
# Checkout the topic branch
git checkout topic-branch-1
# Create a _test_ branch on top of this
git checkout -b test
# Attempt to merge master
git merge master
# resolve conflicts, run it through tests, etc
# then
git commit <conflict-resolving>
# You *could* now even create a separate test branch on top of master
# and see if you are able to merge
git checkout master
git checkout -b master-test
git merge test
最后再次签出主题分支,从测试分支应用修复程序并继续执行PR。最后删除测试和主测试。
卷入的是的,但在我做好准备之前,它不会干扰我的主题或主分支。
如果最终出现合并冲突,并且没有任何要提交的内容,但仍显示合并错误。在应用所有下面提到的命令之后,
git reset --hard HEAD
git pull --strategy=theirs remote_branch
git fetch origin
git reset --hard origin
请删除
.git\index.lock
文件[恢复时剪切粘贴到其他位置],然后根据需要的版本输入以下任意命令。
git reset --hard HEAD
git reset --hard origin
希望这有帮助!!!
自从Git 1.6.1.3以来,Git checkout已经可以从合并的任何一侧进行签出:
git checkout --theirs _widget.html.erb