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

一笑奈何 提交于 2019-12-02 18:03:43

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/*

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}'`

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)

fracz

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!