Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 973
isherwood Avatar asked Jul 23 '14 16:07

isherwood


People also ask

Is it possible to unmerged files git?

Git Pull is Not Possible, Unmerged Files.

How do I accept all incoming changes in git?

Git : accept all incoming changes In the case that you wish accept all incoming changes in the branch, you can cd to the repository and run git against the current directory. (awesome-new-feature) git checkout --theirs .

Does git checkout automatically merge?

git checkout replaces locally changed files. git merge merges local & incoming changes, alerting to any conflicts. Neither if these commands will remove local files that do not exist in the incoming commit.

What is theirs and ours in git?

" ours represents the history and theirs is the new applied commits". In a merge, git takes the current branch and apply the additional commits to it's HEAD. The current branch is the history ours and the additional commits are new theirs . In a rebase, git rewrites the history of the current branch.


2 Answers

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

This may also work, according to helios456:

git checkout --theirs directory_name/. 
like image 135
isherwood Avatar answered Sep 19 '22 22:09

isherwood


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}'` 
like image 35
Ondweb Avatar answered Sep 19 '22 22:09

Ondweb