我不想要一个可视化的合并工具,我也不想在头文件(我的)和导入的更改(他们的)之间手动选择冲突的文件。大多数时候,我要么想要他们的所有更改,要么想要我的所有更改。通常,这是因为我的更改使其上行,并通过拉回给我,但可能在不同的地方略有修改。
有没有命令行工具可以去掉冲突标记,根据我的选择选择所有的方式?或者一组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是否认为合并发生了,所以我不认为这是必要的。
反过来,做“接受他们的”同样是混乱的。我唯一能弄清楚的方法就是:
git show test-branch:Makefile > Makefile; git add Makefile;
这也给了我一个乱七八糟的提交消息,其中有冲突: Makefile两次。
有没有人能指出如何用一种更简单的方式来做上述两个动作?谢谢
发布于 2014-09-10 02:54:45
试试这个:
要接受他们的更改:git merge --strategy-option theirs
接受你的:git merge --strategy-option ours
发布于 2012-08-07 18:25:55
根据Jakub的回答,为了方便起见,您可以配置以下git别名:
accept-ours = "!f() { git checkout --ours -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f"
accept-theirs = "!f() { git checkout --theirs -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f"
它们可以选择一个或多个文件路径来解析,如果没有给出任何路径,则默认解析当前目录下的所有内容。
将它们添加到~/.gitconfig
的[alias]
部分,或者运行
git config --global alias.accept-ours '!f() { git checkout --ours -- "${@:-.}"; git add -u "${@:-.}"; }; f'
git config --global alias.accept-theirs '!f() { git checkout --theirs -- "${@:-.}"; git add -u "${@:-.}"; }; f'
发布于 2013-06-21 12:42:51
根据kynan的回答,以下是相同的别名,修改后的别名可以处理文件名中的空格和首划线:
accept-ours = "!f() { [ -z \"$@\" ] && set - '.'; git checkout --ours -- \"$@\"; git add -u -- \"$@\"; }; f"
accept-theirs = "!f() { [ -z \"$@\" ] && set - '.'; git checkout --theirs -- \"$@\"; git add -u -- \"$@\"; }; f"
https://stackoverflow.com/questions/914939
复制相似问题