How to view history of git subtree?

Viewed 1516

I have two repos (let's call them oldrepo1 and oldrepo2). These two repos have 20k and 21k commits respectively in their current history. I'm merging them together in a new repo, each one under a subdir:

newrepo/oldrepo1

newrepo/oldrepo2

I've used these commands to populate the new repo

git subtree add --message="Migrate oldrepo1" --prefix=oldrepo1 <oldrepo1 url> master

git subtree add --message="Migrate oldrepo2" --prefix=oldrepo2 <oldrepo2 url> master

when I go into the root of newrepo, and run "git --no-pager log --graph --oneline" I get 41k commits, as expected, but if I drill down to any level underneath and run git log all I get is the "Migrate oldrepoX" commit:

For instance, I have a file that has had 60 changes in the original repo, but when I run git log on that same file in the new repo, all I get is:

commit <commitid>
  Author: Me <me@myselfandi.com>
  Date:   Fri Sep 18 23:17:28 2020 -0700

      Migrate oldrepo1

      git-subtree-dir: oldrepo1
      git-subtree-mainline: <somecommitid>
      git-subtree-split: <somecommitid>

I didn't squash any history when I migrated, so why can't I see the 60 commits to this file in the new repo?

2 Answers

when I run git log on that same file ...

You did not show the actual command that you used, but let's suppose, for instance, that it is:

git log path/to/file.ext

or:

(cd path; git log to/file.ext)

which both do the same thing. More generally any git log command that includes a path will do this.

The this in question is called History Simplification (see Git log history simplification, elaborations example in git log's manual). The git log documentation has been improved recently (in commit 8d049e182e2e...), so see that as well. This history simplification can only follow a single file or path through renames, will miss some cases, and generally requires using the --follow option.

Edit: I forgot to mention that git subtree add is a particularly difficult case, for which even --follow doesn't help (usually). The existing --follow option is a horrible hack that really needs to be replaced, but this has been true for more than a decade and a good replacement is hard.

Related