1

I am using the git mergetool command to fix conflicts. However I have thousands of conflicts, is there way to simplify this so I get everything from the remote?

I am asked to enter c, d or a in the command.

{local}: deleted
{remote}: created file
Use (c)reated or (d)eleted file, or (a)bort?

Since I have thousands of files, I don't want to keep sending c. Is there way to just do this in bulk?

Julian
  • 33,915
  • 22
  • 119
  • 174
Shahboz
  • 466
  • 2
  • 10
  • 30
  • You can add `-X theirs` option for `git merge` command (`git merge branch -X theirs`), so there is no need to execute mergetool command since git merge the conflicts automatically. – Marina Liu Mar 19 '18 at 03:14

3 Answers3

2

You can solve this outside of git mergetool: run git status --porcelain to get a list of all unmerged files and their states in machine-readable format.

If your Git is new enough, it will support --porcelain=v2. See the git status documentation for details on the output formats. Output format v2 is generally superior for all purposes, but you should be able to make do with either one.

Next, you must write a program. Unfortunately Git has no supplied programs for this. Your program can be fairly simple depending on the specific cases you want to solve, and you can use shell scripting (sh or bash) as the programming language, to keep it easy.

Since you're concerned about the cases where git mergetool says:

Use (m)odified or (d)eleted file, or (a)bort? 

you are interested in those cases where the file name is missing in the stage 1 ("base") version and also missing in the stage 2 ("local") version, but exists in the stage 3 ("remote") version. (See the git status documentation again and look at examples of your git status --porcelain=v2 output to see how to detect these cases. Two of the three modes will be zero.) For those particular path names, simply run git add on the path name to mark the file as resolved in favor of the created file.

Once you have marked all such files, you can go back to running git mergetool to resolve additional conflicts, if there are any.

Note that your "program" can consist of running:

git status --porcelain=v2 > /tmp/commands.sh

and then editing /tmp/commands.sh to delete all but the lines containing files that you want to git add. Then change all of those lines to read git add <filename> where <filename> is the name of the file. Exit the editor and run sh /tmp/commands.sh to execute all the git add commands. That's your program!

torek
  • 448,244
  • 59
  • 642
  • 775
0

supposing you want their change and modified yours you can do a pull as like:

git pull -X theirs

Other stackOverflow answers

git pull -X

git merge strategies this link will help understand any other merge strategies for the futuro

Angel
  • 1,670
  • 1
  • 11
  • 14
  • `-X theirs` only affects *low level* conflicts; Hashim77 is seeing what I call *high level* conflicts. – torek Mar 16 '18 at 20:10
0

If you want that all the change you did will be deleted and you will be sync with the remote. You should do the following:

git stash
git pull

And if you want to restore the change you did you should type:

git stash pop

Basically 'git stash' is moving the change to a temp repository.

you can learn more in:

NDP software:: Git Cheatsheet

Yosef Alon
  • 78
  • 12