如何为多个文件(或所有未合并的文件)执行“git checkout --theirs”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24916186/
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
How to do 'git checkout --theirs' for multiple files (or all unmerged files)
提问by isherwood
Say I have this after attempting a merge and upon entering git status
:
假设我在尝试合并和输入后有这个git status
:
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# added by them: myfile1.xhtml
# added by them: myfile2.xhtml
# added by them: myfile3.xhtml
... and I know I want to do this for each of those files:
...我知道我想为每个文件执行此操作:
git checkout --theirs myfile1.xhtml
git add myfile1.xhtml
... but there are many of them. How might I do them as a batch?
……但是有很多。我该如何批量处理它们?
采纳答案by isherwood
The solution for my case ended up being to simply use a wildcard in the directory path, since the files were grouped:
我的情况的解决方案最终只是在目录路径中使用通配符,因为文件已分组:
git checkout --theirs directory_name/*
git add directory_name/*
回答by Ondweb
You can use the below commands to checkout multiples files on unmerged path
您可以使用以下命令在未合并路径上检出多个文件
git checkout --theirs `git status | grep "added by them:" | awk '{print $NF}'`
execute the below command to commit the above files
执行下面的命令来提交上面的文件
git commit `git status | grep "added by them:" | awk '{print $NF}'`
回答by kris
If your files are deeper than one directory (ie. there are subdirectories) and you want to selectively recursively choose all their
files for a directory, then use the following:
如果您的文件比一个目录更深(即有子目录)并且您希望有选择地递归选择their
目录的所有文件,请使用以下命令:
grep -lr '<<<<<<<' directory_name/ | xargs git checkout --theirs
git add directory_name/*
(from this page)
(从这个页面)