找到两个git存储库之间的差异

时间:2010-06-19 12:26:20

标签: git

我已经在Github上分叉了一个项目的git存储库,并对它进行了自己的更改。 我想在我的存储库和原始存储库之间获得差异 我已经分叉的存储库。有人能告诉我git命令 获得那种差异? 我需要提交差异进行审核。

原始存储库:

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

我的存储库:

git@github.com:prafullat/hive.git

以下是我.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

我尝试查看有关同一主题的其他帖子问题 无法让它发挥作用。

任何帮助都将受到高度赞赏。

5 个答案:

答案 0 :(得分:15)

您需要获取最新的两个远程存储库并将主要分支相互比较。看起来主分支是“主干”分支,所以你可以看到你的项目所特有的提交(而不是'镜像'项目的主干分支),如下所示:

$ 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

或者您可以删除--oneline以查看完整的提交消息。看起来他们都是你的。如果您不想查看这些合并提交,也可以添加--no-merges

接下来,你可以通过运行这个来获得实际的差异:

$ 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(-)

如果删除--stat,您将获得实际差异。 ...mirror/trunk之间的origin/trunk是一个简写,说你想要共同祖先之间的差异,所以它不会给你一个差异删除所有添加到原始项目的内容你开始了,它只是给你你在你的分支上做的改变。

答案 1 :(得分:5)

如果有人再次遇到这个问题,那么就存在一个缺陷。

[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

每当你在镜像上执行git fetch时,它会覆盖.git / refs / remotes中的同一个远程分支。您应确保更改远程镜像提取以反映新名称。

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

然后一个简单的

git diff origin/master..mirror/master

答案 2 :(得分:3)

手动提交sha1并在diff中使用它们 解决了这个问题!

[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!.......

答案 3 :(得分:2)

git diff origin/master mirror/master

一切都应该可以解决问题。

答案 4 :(得分:0)

上述方法的一个缺点是它们区分了一对特定的分支。如果你想找到本地仓库与遥控器不同的所有提交 - 你可能已创建的所有分支,即使有些尚未合并回主人 - 你可以执行以下操作:

git log --branches --not --remotes