简单的工具来'接受他们'或'接受我的'使用git的整个文件

我不想要一个可视化的合并工具,我也不希望有冲突的文件,并手动select之间的头(我的)和导入的变化(他们)。 大多数时候,我要么想要所有的改变,要么全部改变。 通常这是因为我的变化使得它变得更快,并且正在通过拉回来回到我身上,但是在各个地方可能会稍微修改。

有没有一个命令行工具,可以摆脱冲突标记,并根据我的selectselect一种或另一种方式? 或者一组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是否认为合并发生了,所以我认为这不一定行得通。

换个angular度来说,“接受他们”也是一团糟。 我能弄明白的唯一方法是:

 git show test-branch:Makefile > Makefile; git add Makefile; 

这也给了我一个搞砸的提交消息,其中有两次冲突:Makefile。

有人可以指出如何以更简单的方式做上述两个行动? 谢谢

解决scheme非常简单。 git checkout <filename>试图从索引中检出文件,因此在合并时失败。

你需要做的是(即签出一个提交 ):

要检出您自己的版本,您可以使用以下之一

 git checkout HEAD -- <filename> 

要么

 git checkout --ours -- <filename> 

要么

 git show :2:<filename> > <filename> # (stage 2 is ours) 

要检出另一个版本,您可以使用以下之一

 git checkout test-branch -- <filename> 

要么

 git checkout --theirs -- <filename> 

要么

 git show :3:<filename> > <filename> # (stage 3 is theirs) 

您还需要运行“添加”将其标记为已解决:

 git add <filename> 

基于Jakub的答案,你可以configuration下面的git别名为了方便:

 accept-ours = "!f() { git checkout --ours -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f" accept-theirs = "!f() { git checkout --theirs -- \"${@:-.}\"; git add -u \"${@:-.}\"; }; f" 

他们可以select一个或几个path的文件来解决,并默认解决当前目录下的所有内容,如果没有给出。

将它们添加到~/.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' 

尝试这个:

接受他们的变化: git merge --strategy-option theirs

接受你的: git merge --strategy-option ours

基于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"