How to do 'git checkout --theirs' for mult

2020-05-18 07:09发布

Say I have this after attempting a merge and upon entering 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?

4条回答
Ridiculous、
2楼-- · 2020-05-18 07:33

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}'`
查看更多
孤傲高冷的网名
3楼-- · 2020-05-18 07:38

This checks out all unmerged files without specifying the directory:

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

Source

查看更多
再贱就再见
4楼-- · 2020-05-18 07:43

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:

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

(from this page)

查看更多
Emotional °昔
5楼-- · 2020-05-18 07:45

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/*
查看更多
登录 后发表回答