Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

powershell - How can I accept all remote files in a specific folder during a git merge?

We're using posh-git on Windows Powershell for source control.

We're in the unenviable position of storing some of our built assemblies in our git repo. I know all the sermons on why you shouldn't do that, but we have to live with it for now. Thankfully they are in a separate solution, but sometimes two people work on that solution in their own branch simultaneously, and the last one in gets to take the merge conflict. The process, of course, looks something like this:

  1. Person A lands their changes on develop.
  2. Person B merges those changes, which include both assemblies and update source code.
  3. Person B resolves conflicts, as has to confirm which version of each assembly they want to keep. This is annoying and time-consuming, and also unnecessary since Person B will rebuild the assembly after merging the source code anyway.
  4. Person B rebuilds the assemblies and makes a new commit to finish the merge.

The assemblies are in a folder in our Repo: /Source/Foundation Assemblies/

Person B cannot just take all changes from the remote, since their branch may have conflicting changes, but it would be helpful to just "take theirs" or "take mine" for the /Source/Foundation Assemblies/ folder only. Is this something that can be done with git?

A command line example would be helpful. Normally, the merge would just be:

git merge develop

I was thinking it might be possible to .gitignore the /Source/Foundation Assemblies/ folder, and then remove it from the .gitignore after the merge, but that is three steps. If we could do it in one from the command line, that would be GREAT!!!

Any help appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do git merge develop -X theirs, and all conflicts will take the remote branch's copies.

Edit: Looking back over your question I see that you only want to take "theirs" for a particular subfolder. In that case, after git merge develop, do git checkout --theirs /Source/Foundation Assemblies/. This will replace the contents of that folder with "theirs". Then just git add /Source/Foundation Assemblies/ and you are good to go.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...