14

I have a repository that has mounted another repository with

git subtree add -P some/path  otherremote otherbranch

development has gone on with some local changes, but also with a few rounds of merges done with:

git fetch otherremote
git subtree merge -P some/path otherremote/otherbranch
git commit

Now I want to get a diff between the HEAD of otherremote/otherbranch and the tree at some/path. How can I do this?

mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81
gregw
  • 2,354
  • 20
  • 21

1 Answers1

14

This should be what you're looking for:

git diff otherremote/otherbranch commit:some/path

You can even compare against previous revisions, using all the standard commit naming conventions.

For example, I've made a remote repo u-boot, master branch, a subtree of my main repo at u-boot/. To see the changes I've made in my local master branch since a specific version in the remote repo:

git diff u-boot/master~17 master:u-boot/

Tested using git 1.9.0, though I'm pretty sure this generally works with older versions as well.

HobbesAtPlay
  • 141
  • 4
  • 1
    For the record, if the remote has changed, the diff will still show the results from the outdated branch unless we `git remote update` or `git subtree pull` again (the latter is merging too). The same happens even if we pushed to the remote from the very same subtree. – Wtower Feb 26 '15 at 14:30
  • 1
    In your example, what does the ~17 represent? – Costin_T Dec 29 '15 at 11:36
  • FTR: `~17` means "go back by 17 revisions". So this is using the commit 17 commits before master. – Flamefire Nov 11 '19 at 13:23
  • To (potentially) clarify through abstraction: `git diff subtree-remote/commitish commitish:subtree_path_prefix/`, where `subtree_path_prefix` is the directory that contains the root of the subtree repository. So if you had a project called `barproj`, a subtree in that project that was off its root in a directory called `foosub`, and a remote called `foorepo` for that subtree, then to compare the HEAD of main on the remote with your local repo, you'd run `git diff foorepo/main main:foosub` in the `barproj` directory. – chb Jun 01 '23 at 18:33