查找两个 git 存储库之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3075460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding diff between two git repositories
提问by Prafulla
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.
我在 Github 上分叉了一个项目的 git 存储库,并对其进行了自己的更改。我想在我的存储库和我分叉的原始存储库之间获得一个差异。有人可以告诉我 git 命令来获取差异吗?我需要提交差异以供审核。
Original repository:
原始存储库:
git://github.com/apache/hive.git
My repository:
我的存储库:
[email protected]:prafullat/hive.git
Here are the details from my .git/config
这是我的详细信息 .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.
任何帮助将不胜感激。
采纳答案by Prafulla
Getting commit sha1 manually and using them in diff solved the problem!
手动获取 commit 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!.......
回答by Scott Chacon
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.
或者您可以删除--oneline
以查看完整的提交消息。看起来它们都是你的。--no-merges
如果您不想看到这些合并提交,您也可以添加。
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.
如果删除--stat
,您将获得实际差异。在...
中之间mirror/trunk
和origin/trunk
是一个速记说你想要的共同祖先之间的差异,因此它不会给你一个差异消除一切加到原来的项目,因为你开始,它只是给你你上所做的更改您的分支。
回答by Rob Adams
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.
每当您在镜像上执行 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
Then a simple
然后一个简单的
git diff origin/master..mirror/master
回答by poke
git diff origin/master mirror/master
Something along that should do the trick.
一些东西应该可以解决问题。
回答by peterflynn
One downside of the approaches above is that they diff a specific pair of branches. If you want to find allcommits 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