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
1.2k views
in Technique[技术] by (71.8m points)

merge - git-subtree pull complications

We have been trying to get git-subtree working on a project (with git version 1.7.9.4) and have run into a bit of a complication. Someone else previous added the subtree with this command some months ago:

git subtree add --prefix=foo [email protected]:foo.git master

Now there have been substantive changes to foo and we'd like to merge in those changes, ideally squashing them in. None of the files have been modified since they were imported.

I've tried three things to try and merge in the changes.

First:

git subtree pull --squash -P foo [email protected]:foo.git master

Which throws the exception: Can't squash-merge: 'foo' was never added.

Second:

git subtree pull -P foo [email protected]:foo.git master

This works (sort of), but has the issue of pulling in all of the commits and has conflicts with the files that have been modified.

Finally, I tried this:

git pull --squash -s subtree [email protected]:foo.git  master

This gives me the desired result, with the output Automatic merge went well; stopped before committing as requested and all of the files showing up as modified (with the correct content).

Ideally I'd like to continue using first git-subtree version and get an output close to the last version. If we have to use the last version consistently going forward, we will, but I am a little confused as to why the last one doesn't produce merge conflicts while the middle one does.

Any help is appreciated.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I had the same problem, and in my case it seems to be due to the initial subtree commit being merge-squashed into the master branch.

Looking through the subtree source I found this: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224

It looks like subtree greps your git log for git-subtree-dir: foo but doesn't find a suitable commit. Try git log --grep="git-subtree-dir: foo/*$", and if there's something weird with that commit, such as it being a merge commit, that could be the issue.

Just pulling without squashing worked for me, apart from the annoying merge conflicts. I did that in a temporary branch which I then git merge --squashed into another branch to avoid a messier history. It could've been rebased instead too of course.


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

...