在 git merge 中,你如何用 git 说有冲突的版本替换你的版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3515657/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:30:20  来源:igfitidea点击:

In a git merge, how do you just replace your version with the version git says there is a conflict with?

gitmerge

提问by Rishi

I have two files: A and B. If I have been working on A and a partner is working on B, I want to merge files A and B. B is already committed. Let's say my partner already made the changes I was working on, so I just want to replace my A file with their B file - no merge needed. How do I resolve the conflict with git?

我有两个文件:A 和 B。如果我一直在处理 A 而合作伙伴正在处理 B,我想合并文件 A 和 B。B 已经提交。假设我的合作伙伴已经进行了我正在进行的更改,所以我只想用他们的 B 文件替换我的 A 文件 - 不需要合并。如何解决与 git 的冲突?

Thanks!

谢谢!

回答by Droopycom

If their is a conflict during a merging operation (merge, cherry-pick, rebase, etc...) you can resolve conflict by picking one side of the changes by doing :

如果它们在合并操作(合并、挑选、变基等)期间发生冲突,您可以通过执行以下操作来选择更改的一侧来解决冲突:

git checkout --ours <path>(this will choose the local changes)

git checkout --ours <path>(这将选择本地更改)

or

或者

git checkout --theirs <path>(this will choose the remote changes)

git checkout --theirs <path>(这将选择远程更改)

then finishing resolving the conflict as usual with:

然后像往常一样完成解决冲突:

git add <path>

then commit with:

然后提交:

git commit

回答by cmcginty

Let's say both you and your partner modified the same file, and is committed to each respective repository.

假设您和您的合作伙伴都修改了同一个文件,并提交到每个相应的存储库。

git pull                             # fetch/merge partners changes
# merge fails, conflict
git checkout origin FILE_TO_REPLACE  # replace changes with partners ver
git commit                           # finish merge