如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
如何解决git合并冲突以支持拉取的更改?
我希望从工作树中删除所有冲突的更改,而不必使用gitmergetool处理所有冲突,同时保持所有无冲突的更改。最好是,我想在拉的时候做,而不是事后。
当前回答
我有一个长期运行的下一个版本分支,对开发时更改的文件、在两个分支的不同位置添加的文件等进行了大量删除。
我想将下一个版本分支的全部内容进行开发,所有内容都在一次巨大的合并提交中。
对我有效的上述命令组合是:
git merge -X theirs next-version
# lots of files left that were modified on develop but deleted on next-version
git checkout next-version .
# files removed, now add the deletions to the commit
git add .
# still have files that were added on develop; in my case they are all in web/
git rm -r web
这不是一个新的答案,只是结合了许多答案中的一部分,部分是为了保证你可能需要所有这些答案。
其他回答
要解决与特定分支中版本的所有冲突,请执行以下操作:
git diff --name-only --diff-filter=U | xargs git checkout ${branchName}
因此,如果您已经处于合并状态,并且希望保留冲突文件的主版本:
git diff --name-only --diff-filter=U | xargs git checkout master
git pull -s recursive -X theirs <remoterepo or other repo>
或者,简单地说,对于默认存储库:
git pull -X theirs
如果你已经处于冲突状态。。。
git checkout --theirs path/to/file
2023年更新!
如果您想接受所有当前更改并忽略任何传入的更改,可以执行以下操作:
git merge [branch] --strategy-option ours
[branch]应替换为要合并到当前分支中的分支的名称。
相反,如果您知道要覆盖任何当前更改并接受来自传入更改的所有冲突,则可以使用他们的策略:
git merge [branch] --strategy-option theirs
如果您已经处于冲突状态,并且不想逐个签出路径。你可以试试
git merge --abort
git pull -X theirs
解决了。通过以下简单步骤解决所有冲突。
git fetch && git reset --hard origin/master
git pull -X theirs
git pull origin master