Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a git subtree diff?

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?

like image 415
gregw Avatar asked Feb 24 '14 00:02

gregw


People also ask

How do you pull a subtree?

Adding a subtreeSpecify the prefix local directory into which you want to pull the subtree. Specify the remote repository URL [of the subtree being pulled in] Specify the remote branch [of the subtree being pulled in] Specify you want to squash all the remote repository's [the subtree's] logs.

Is subtree better than submodule git?

If there is an external repository you own and are likely to push code back to, use Git submodule since it is easier to push. If you have third-party code that you are unlikely to push to, use Git subtree since it is easier to pull.

What are git Subtrees?

A Git subtree is a replica of a Git repository that has been dragged into the main repository. A Git submodule is a reference to a particular commit in a different repository. Git subtrees, which were first introduced in Git 1.7. 11, help you make a copy of any repo into a subdirectory of another.

What is git subtree split?

Splitting the Original Repository The subtree commands effectively take a folder and split to another repository. Everything you want in the subtree repo will need to be in the same folder.


1 Answers

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.

like image 93
HobbesAtPlay Avatar answered Oct 16 '22 13:10

HobbesAtPlay