gitgit-subtree

Git subtree conflict resolution


I have used Git for a long time but I am new to submodule/subtree and have to use it now. So I created a new repo to be used as a child repo. Then did the following:

  1. Created a subtree within a new (child) repo from existing main repo git subtree add -P MainRepo Development
  2. Posted a commit on a child side and dropped some files from within a child repo. Now when pulling main repo changes git subtree pull -P MainRepo Development I am getting conflicts since some files are deleted on a child repo side. This is an error example:
CONFLICT (modify/delete): CancellationRepository.cs deleted in HEAD and modified in
73b8646642887c850f5def4984778c3f36de90f. Version 673b8646642887c850f5def4984778c 
CancellationRepository.cs left in tree.
Automatic merge failed; fix conflicts and then commit the result.

Is there a way to setup subtree that conflicts are always silently resolved to a child side/deleted version?

Git repos are hosted within Azure Devops.


Solution

  • The answer to the question "setup subtree that conflicts are always silently resolved to a child side" is: The git subtree script in contrib seems not to support this as of 2025:

    cmd_pull () {
        if test $# -ne 2
        then
            die "fatal: you must provide <repository> <ref>"
        fi
    

    Even if you manage to do it some other way, you state your goal is to automate DevOps pipelines. At some point this will break, because -X theirs will get something wrong at some point. E.g. a lib dependency, a change to a file that depends on the deleted files, or some moved file etc.

    However, to automate your DevOps pipeline, while removing the undesired files, there are ways to achieve it, which are probably simpler than bending subtree to suit your needs. If I got your requirements correctly, I'd do something like:

    If this does not work, I'd suggest you write the actual Y-Problem in a separate question or forum.