22

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:

git@github.com:prafullat/hive.git

Here are the details from my .git/config

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com: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.

Willem van Ketwich
  • 5,666
  • 7
  • 49
  • 57
Prafulla
  • 832
  • 1
  • 7
  • 17
  • possible duplicate of [How do I compare two git repositories?](http://stackoverflow.com/questions/687450/how-do-i-compare-two-git-repositories) – Ciro Santilli OurBigBook.com Aug 30 '14 at 18:20
  • Possible duplicate of [Getting the difference between two repositories](http://stackoverflow.com/questions/1968512/getting-the-difference-between-two-repositories) – Rumid Feb 16 '17 at 10:27

5 Answers5

15

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 git@github.com: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.

Scott Chacon
  • 2,756
  • 19
  • 14
  • Good detailled explanation. +1. On the '`...`' syntax, see http://stackoverflow.com/questions/2539040/not-able-to-think-of-a-case-where-git-diff-master-lab-and-git-diff-master-lab and http://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git/53573#53573, and the very complete answer: http://stackoverflow.com/questions/850607/difference-in-git-log-origin-master-vs-git-log-origin-master – VonC Jun 19 '10 at 15:44
  • I keep on getting following error. How do I fix it ? [prafulla@prafulla-laptop hive] $git log --oneline origin/trunk ^mirror/trunk warning: refname 'origin/trunk' is ambiguous. warning: refname 'mirror/trunk' is ambiguous. – Prafulla Jun 20 '10 at 03:56
  • It looks like you might have accidentally created a local tracking branch named 'origin/trunk', which is common, and unfortunate that git even lets you do it. You can fix that by running `git log refs/remotes/origin/trunk ^mirror/trunk` instead - that will make it non-ambiguous. I would tell you to delete your local (`refs/heads/origin/trunk`) reference, but you might have work on it, I would have to see all of your references. You can run `git for-each-ref` and paste the output here and I can tell you if you can safely delete it. – Scott Chacon Jun 20 '10 at 17:46
  • it might also be worth taking some time and reading something like Pro Git (http://progit.org/book) to learn Git a bit better if you're doing this much work in it. – Scott Chacon Jun 20 '10 at 17:47
5

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

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com: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
Rob Adams
  • 450
  • 3
  • 5
3

Getting commit sha1 manually and using them in diff solved the problem!

[prafulla@prafulla-laptop .git] $cd refs/remotes/
[prafulla@prafulla-laptop remotes] $cat origin/trunk
1c4fa827f4fad2aad67a4fa5b57d88afe51d1559
[prafulla@prafulla-laptop remotes] $cat mirror/trunk 
14f5fb7cba7bef466727a5b721c7c202e80e5dfd
[prafulla@prafulla-laptop remotes] $git diff 14f5fb7cba7bef466727a5b721c7c202e80e5dfd 1c4fa827f4fad2aad67a4fa5b57d88afe51d1559
.......
.... diff follows!.......

Prafulla
  • 832
  • 1
  • 7
  • 17
2
git diff origin/master mirror/master

Something along that should do the trick.

poke
  • 369,085
  • 72
  • 557
  • 602
  • 9
    It gives this error. git diff remotes/origin remotes/mirror fatal: ambiguous argument 'remotes/origin': unknown revision or path not in the working tree. Use '--' to separate paths from revisions – Prafulla Jun 19 '10 at 12:31
0

One downside of the approaches above is that they diff a specific pair of branches. If you want to find all commits where your local repo differs from the remote -- across all branches you may have created, even if some aren't merged back into master yet -- you can do the following:

git log --branches --not --remotes
peterflynn
  • 4,667
  • 2
  • 27
  • 40
  • This is useful. How do you reverse it so that it shows you all the unmerged branches in the remote that differ from your local repo? – davidA Sep 12 '16 at 22:51