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

后端 未结 3 1095
不知归路
不知归路 2020-12-21 13:10

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 al

相关标签:
3条回答
  • 2020-12-21 13:32

    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.

    0 讨论(0)
  • 2020-12-21 13:33

    You have several merge strategies which you can use:

    resolve

    This can only resolve two heads (i.e. the current branch and another branch you pulled from) using a 3-way merge algorithm. It tries to carefully detect criss-cross merge ambiguities and is considered generally safe and fast.

    recursive

    This can only resolve two heads using a 3-way merge algorithm. When there is more than one common ancestor that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. This has been reported to result in fewer merge conflicts without causing mismerges by tests done on actual merge commits taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames. This is the default merge strategy when pulling or merging one branch.

    The 'recursive' strategy can take the following options:

    ours

    This option forces conflicting hunks to be auto-resolved cleanly by favoring 'our' version. Changes from the other tree that do not conflict with our side are reflected to the merge result. For a binary file, the entire contents are taken from our side.

    This should not be confused with the 'ours' merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring 'our' history contains all that happened in it.

    theirs

    This is the opposite of 'ours'.

    and even more but those are the main ones.

    0 讨论(0)
  • The "right" way in your case is to rebuild the assemblies before committing the merge. I don't see why you would not do this. The steps as follows should work:

    1. resolve and git add all conflicted sources. Then whatever happens during merge should not affect what you commit.
    2. remove the conflicted assembly files. No need to do anything with their git information, just remove the files
    3. build the assemblies.
    4. git add the ready assemblies.
    5. Then commit. What you get is merge which includes both local and remote changes.

    EDIT: try this:

    1. git rm --force -r <dirname>
    2. run your mergetool, now it should now mention the binary files (kdiff3 did not)
    3. build assemblies
    4. git add <dirname>
    5. commit

    I tried this bash script to reproduce you case as I understand it.

    0 讨论(0)
提交回复
热议问题