Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git-subtree without squash: view log

I merged a tree onto a my repository by using git subtree add without the squash option. A git log shows that the commits were successfully added to the repository. However, if I do a git log --follow filename, the history stops at the merge and does not show previous commits. I tried using -M instead of --follow and that doesn't work either. How can I get a log of the commits for a specific file or files from before the merge?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The commit created by git subtree merge or git subtree add does an "add" for the files coming from the subtree, not a "move". This means that their history cannot be tracked as with other merges or movements.

History for the file you want can still be displayed by looking directly in the subtree before the merge. If your workspace is the merge commit that git subtree created then the second parent of it (HEAD^2) will be the last commit of the original subtree. From here you can see the contents of the original subtree:

# Display the contents of the original subtree
git ls-tree HEAD^2

From this commit you can track the changes of the file you are interested. Be careful that the path of your file will be different within the subtree that in your workspace. You will need to remove the --prefix given to git subtree in order to have the correct path for your file.

git log HEAD^2 --follow -- path-in-subtree/file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...