How to fix merge conflicts for a lot of files in git?
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?
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!
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
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
链接地址: http://www.djcxy.com/p/45036.html上一篇: 如何合并git中的子目录?
下一篇: 如何解决git中的大量文件的合并冲突?