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

Categories

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

merge - Git confused when merging an update into my subtree

We previously used many submodules in our main repositories, but to increase the maintainability of our projects we started an experimental branch where we replaced them all with subtrees.

This worked good - but now when I'm trying to update one of the subtrees it erroneously merges the update into a completely wrong directory that isn't even a subtree.

The main repository, where the branch "subtree" contains the experimental branch, is: git://github.com/hugowetterberg/goodold_drupal.git

The repository to merge in updates from: git://github.com/voxpelli/drupal-oembed.git

Merging by doing: git merge -s subtree oembed/master

The path the updates should be merged into: sites/all/modules/oembed/

The path they are merged into: modules/aggregator/translations/

Anyone having an idea of how to get the updates into the subtrees or what the error can be?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Unfortunately this is a bug (or missing feature) in the "git merge -s subtree" code. It actually guesses the subtrees that you want to merge. Usually, this magically turns out to be correct, but if your subtree contains a lot of changes (or was originally empty, or whatever), then it can fail spectacularly.

The best way to work around it is:

  1. Merge the files as you did above.

  2. Manually move all the resulting files to where they should have gone.

  3. git commit -a --amend to correct the merge commit.

Future merges will probably work fine, unless this directory is constantly in unbelievable amounts of flux.

The experimental "git subtree" command has a --prefix parameter that should let you override this, but unfortunately it doesn't work at the moment (since it requires working around "git merge -s subtree" features and there hasn't been time to do it).

Anyway, this should be a rare situation and the workaround won't be needed even for future merges of the same project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...