如何为多个文件(或所有未合并的文件)执行“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

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

How to do 'git checkout --theirs' for multiple files (or all unmerged files)

gitgit-checkoutgit-add

提问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 theirfiles for a directory, then use the following:

如果您的文件比一个目录更深(即有子目录)并且您希望有选择地递归选择their目录的所有文件,请使用以下命令:

grep -lr '<<<<<<<' directory_name/ | xargs git checkout --theirs
git add directory_name/*

(from this page)

(从这个页面

回答by fracz

This checks out all unmerged files without specifying the directory:

这会在不指定目录的情况下检查所有未合并的文件:

git ls-files --unmerged | perl -n -e'/\t(.*)/ && print "\n"' | uniq | xargs -r git checkout --theirs --

Source

来源