Bryan Larsen Bryan Larsen - 1 year ago 165
Git Question

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
instead of
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?

Answer Source

Actually, git log --follow should work with subtree merges, but it is known to be hackish for a long time [1-3].

One can stick with subtree merges and rest asured that the strategy is valid for tracking multiple histories, and patiently wait for the unavoidable event that git log --follow will improve. This may actually be a viable decision, since at present git log --follow can see some history in very useful cases. Say you moved a file from the toplevel repo to a sub-repo, then it can track the full move. When you want to track the history that is specific to a sub-repo, you really have to have a separate copy or check out a sub-repo branch.

Alternatives and Workarounds

You can get logs for the files like this [1]:

git log -- '*filename'          # from the toplevel

This views each commit that touched a file whose name ends with filename. It won't follow actual renames, and may show false positive if you have several files with the same basename [1].

You can also merge the repositories using different strategies. Ref [4] shows a way to do this which is very close to what you have with tree merging, but with traceable histories. Basically, you:

  1. add, fetch and merge each sub-repository to the toplevel repository as a regular remote, no git subtree or readtree. At first, this will polute your root dir as if it was theirs, so this is to be done at the begining of a project's life.
  2. git mv the sub-repo files to separate folders


  • upstream changes can be fetched and merged normally, but with the -Xsubtree flag to git merge
  • other cases should be similar, like pushing. (haven't tested it yet)


[1] From the git mailing list

[2] From the git mailing list

[3] git log --follow has been in Google Summer of Code


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download