Git merge --theirs ALL files EXCEPT the ones that have been edited by <name>, <name>, or <name>, in which case I'll fix merge conflicts myself?

StackOverflow https://stackoverflow.com/questions/19232530

  •  30-06-2022
  •  | 
  •  

Domanda

I have two branches, master and upstream, with thousands of files to merge and an equal number of merge conflicts.

Thing is, 90% of the upstream ("theirs") files are the ones I want to keep. Rather than "git mergetool"ing all of them, is there a way to automatically use all of the upstream files, UNLESS the file has been edited by specific people? That way, I can work out the merge conflicts manually myself with only a dozen or so files.

Here's how the pseudo code could work, in my mind:

git checkout master
git merge upstream --squash --all-of-theirs-except firstguy@mail.com secondguy@mail.com
git mergetool //For the remaining conflicts
git push origin master
È stato utile?

Soluzione

Before you do git mergetool, you can checkout the files from the upstream. Then you can use git mergetool to resolve the conflicts for the rest of the files.

git merge upstream squash
git checkout upstream -- <files that you want as "theirs">
git mergetool //Resolve the remaining conflicts.

To get the list of files, you can use git log --author=<email> --name-only --oneline and parse the output to get list. Or you can do git checkout -- path/to/a/directory/ to checkout all the files from a specific directory without having to specifying all the files individually.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top