我不想要可视化 merge 工具,我也不希望必须 vi 冲突文件并手动在 HEAD(我的)和导入的更改(他们的)之间进行选择。大多数时候,我要么想要他们的所有更改,要么想要我的所有更改。通常这是因为我的更改使其上游并通过 pull 返回给我,但可能会在不同的地方稍作修改。
是否有一个命令行工具可以消除冲突标记并根据我的选择选择所有方式?或者一组 git 命令,我可以给自己起别名来执行每一个命令。
# accept mine
alias am="some_sequence;of;commands"
alias at="some_other_sequence;of;commands"
这样做很烦人。 对于“接受我的”,我已经尝试过:
randy@sabotage ~/linus $ git merge test-branch
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
Automatic merge failed; fix conflicts and then commit the result.
randy@sabotage ~/linus $ git checkout Makefile
error: path 'Makefile' is unmerged
andy@sabotage ~/linus $ git reset --hard HEAD Makefile
fatal: Cannot do hard reset with paths.
我应该如何摆脱这些变化标记?
我能做到:
git reset HEAD Makefile; rm Makefile; git checkout Makefile
但这似乎有点迂回,一定有更好的办法。在这一点上,我不确定 git 是否认为 merge 发生了,所以我认为这不一定有效。
反过来说,“接受他们的”同样是一团糟。 我能弄清楚的唯一方法是:
git show test-branch:Makefile > Makefile; git add Makefile;
这也给了我一个困惑的提交消息,其中有两次 Conflicts: Makefile。
有人可以指出如何以更简单的方式执行上述两个操作吗?谢谢
最佳答案
解决方法很简单。 git checkout <filename>
尝试从索引 check out 文件,因此 merge 失败。
您需要做的是(即 checkout 一个提交):
要检查您自己的版本,您可以使用一个:
git checkout HEAD -- <filename>
或
git checkout --ours -- <filename>
(警告!:如果您要 rebase --ours
和 --theirs
会被交换。)
或
git show :2:<filename> > <filename> # (stage 2 is ours)
要 checkout 其他版本,您可以使用以下一个:
git checkout test-branch -- <filename>
或
git checkout --theirs -- <filename>
或
git show :3:<filename> > <filename> # (stage 3 is theirs)
您还需要运行“添加”以将其标记为已解决:
git add <filename>
关于git - 使用 git 对整个文件进行 'accept theirs' 或 'accept mine' 的简单工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/914939/