Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding diff between two git repositories

Tags:

I have forked the git repository of a project on Github and made my own changes to it. I wanted to get a diff between my repository and the original repository that I've forked. Can someone tell me the git command to get that diff? I need to submit the diff for review.

Original repository:

git://github.com/apache/hive.git 

My repository:

[email protected]:prafullat/hive.git 

Here are the details from my .git/config

[remote "origin"]     fetch = +refs/heads/*:refs/remotes/origin/*     url = [email protected]:prafullat/hive.git [remote "mirror"]     fetch = +refs/heads/*:refs/remotes/origin/*     url = git://github.com/apache/hive.git 

I tried looking at other posted questions regarding the same topic and could not get it to work.

Any help would be highly appreciated.

like image 265
Prafulla Avatar asked Jun 19 '10 12:06

Prafulla


People also ask

How do I compare two repositories in Visual Studio?

To compare any two commits in your branch, use the Ctrl key to select the two commits that you want to compare. Then right-click one of them and select Compare Commits. Similar to Commit Details, you can use the Open in New Tab button to open the comparison on a different tab or maximize it on the screen.

How do I compare two GitHub branches?

Comparing branches is as easy as selecting the “compare to branch” option while perusing the feature branch you'd like to compare to another. The compare to branch option in GitHub Desktop is located under the “Branch” in the main menu at the top of the interface.


2 Answers

You need to fetch the latest of both remote repositories and compare the main branches to each other. It looks like the main branch is the 'trunk' branch, so you can see what commits are unique to your project (and not in the trunk branch of the 'mirror' project) like this:

$ git log --oneline origin/trunk ^mirror/trunk 1c4fa82 1. Modified the flag name for gb_to_idx rewrite to    hive.ql.rewrite.gb_to_idx    So 638be54 Merge branch 'trunk' of [email protected]:prafullat/hive into trunk 72c8220 HIVE-1383. Allow HBase WAL to be disabled (John Sichi via Ning Zhang) a372259 Checking in commented meta-data methods in GbToCompactSumIdxRewrite. It has to be unc 33c1fb1 Fixing some files due to wrong application of patch. Build now compiles ! 5942728 Reverting files which were patched twice in last checkin. 5efda04 Adding inital rewrite changes. This patch adds basic query rewrite support to Hive. I 3fce190 Merge branch 'trunk' of git://github.com/apache/hive into trunk b3f9ff2 Checking in commented meta-data methods in GbToCompactSumIdxRewrite. It has to be unc d89deb9 Fixing some files due to wrong application of patch. Build now compiles ! 11db7da Reverting files which were patched twice in last checkin. 88fee30 Adding inital rewrite changes. ba7703f Some part of last check-in got missed. 2c5c5ae Checking initial changes for Hive indexing from He Yongqiang (Hive-417) Here is descr 

Or you can remove the --oneline to see the full commit messages. It looks like they're all yours. You can also add a --no-merges if you don't want to see those merge commits.

Next, you can get the actual diff by running this:

$ git diff --stat mirror/trunk...origin/trunk  README.txt                                         |    4 +-  build.xml                                          |    1 +  .../java/org/apache/hadoop/hive/conf/HiveConf.java |    1 +  ivy/ivysettings.xml                                |    4 +-  metastore/if/hive_metastore.thrift                 |   12 +-  .../apache/hadoop/hive/metastore/api/Index.java    |   15 +-  .../hive/metastore/api/ThriftHiveMetastore.java    |  671 +++++++++++++++++++-  metastore/src/gen-php/hive_metastore_types.php     |   30 +-  .../hadoop/hive/metastore/HiveMetaStore.java       |  155 ++++-  .../hadoop/hive/metastore/HiveMetaStoreClient.java |    9 +-  .../hadoop/hive/metastore/IMetaStoreClient.java    |   14 +  .../hadoop/hive/metastore/MetaStoreUtils.java      |   31 + (bunch more lines)  ql/src/test/queries/clientpositive/index_compact.q |   13 +  .../test/queries/clientpositive/index_projection.q |   13 +  ql/src/test/queries/clientpositive/index_summary.q |   13 +  .../queries/clientpositive/ql_rewrite_gbtoidx.q    |    9 +  .../results/clientpositive/index_compact.q.out     |   70 ++  .../clientpositive/ql_rewrite_gbtoidx.q.out        |  211 ++++++  .../primitive/PrimitiveObjectInspectorUtils.java   |   29 +-  57 files changed, 4000 insertions(+), 131 deletions(-) 

If you remove the --stat, you'll get the actual diff. The ... in between the mirror/trunk and origin/trunk is a shorthand saying you want the diff between the common ancestor, so it doesn't give you a diff removing everything added to the original project since you started, it just gives you the changes you've made on your branch.

like image 95
Scott Chacon Avatar answered Sep 19 '22 17:09

Scott Chacon


There is a flaw in this, in case anyone comes across this question again.

[remote "origin"]     fetch = +refs/heads/*:refs/remotes/origin/*     url = [email protected]:prafullat/hive.git [remote "mirror"]     fetch = +refs/heads/*:refs/remotes/origin/*     url = git://github.com/apache/hive.git 

Whenever you do a git fetch on mirror it overwrites the same remote branch in your .git/refs/remotes. You should make sure to change the remote mirror fetch to reflect the new name.

[remote "origin"]     fetch = +refs/heads/*:refs/remotes/origin/*     url = giturl [remote "mirror"]     fetch = +refs/heads/*:refs/remotes/mirror/*     url = giturl 

Then a simple

git diff origin/master..mirror/master 
like image 32
Rob Adams Avatar answered Sep 17 '22 17:09

Rob Adams