admin管理员组文章数量:1313599
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:
- Created a subtree within a new (child) repo from existing main repo
git subtree add -P MainRepo Development
- 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.
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:
- Created a subtree within a new (child) repo from existing main repo
git subtree add -P MainRepo Development
- 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.
Share Improve this question edited Feb 4 at 2:58 Victor asked Jan 30 at 19:02 VictorVictor 9533 gold badges29 silver badges54 bronze badges 9 | Show 4 more comments3 Answers
Reset to default 1The 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:
- For DevOps clone mainRepo (or shallow clone if repo size is big)
- Run a script/pipeline/something automated to remove the undesired files
- Run your DevOps automation
- If you need to do edits in the DevOps/ChildRepo do them on a separate branch that you merge manually, using your preferred merge strategy
If this does not work, I'd suggest you write the actual Y-Problem in a separate question or forum.
Try this:
git pull -X theirs
- This is a straightforward and effective solution. Did you try this? If so, what error did you encounter?
You can perform the merge manually instead of relying on git subtree pull
so that you can pass custom merge options.
For example, if you want Git to favor your current branch (the child side) when conflicts occur, you can do something like:
# Fetch the latest changes from the main working repository
git fetch <main-repo-remote> Development
# Merge the fetched commit using the subtree merge strategy and telling Git to prefer "ours" in case of conflict
git merge -s subtree -X ours FETCH_HEAD
Here, the -X ours
option tells Git that if there is a conflict, it should take the version from the current branch (your child repo). This should automatically resolve the kind of conflict where a file has been deleted on your side.
Note: The -X ours option works on conflicting hunks and should resolve your “modify/delete” conflict in favor of the deletion. However, make sure you test it carefully to be sure that it works for your entire subtree.
本文标签: Git subtree conflict resolutionStack Overflow
版权声明:本文标题:Git subtree conflict resolution - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741941934a2406193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-X
: stackoverflow/questions/10697463/… ? – Mo_ Commented Feb 2 at 20:38git pull
butgit subtree pull
doesn't have that option. – Victor Commented Feb 2 at 22:45