克隆和原始远程存储库之间的git diff

时间:2011-03-02 02:33:54

标签: git version-control github

我克隆了一个github存储库,并没有在本地进行任何更改。 Github存储库在同一分支上提交了提交。

  1. 如何在本地存储库和原始github存储库之间找到差异?
  2. 如何在我的工作副本和原始github存储库之间找到差异?
  3. 如何在本地存储库和同一项目的另一个github存储库之间找到差异?

3 个答案:

答案 0 :(得分:157)

1)添加您要比较的所有远程存储库:

git remote add foobar git://github.com/user/foobar.git

2)更新遥控器的本地副本:

git fetch foobar

获取不会更改您的工作副本。

3)将您本地存储库中的任何分支与您添加的任何远程数据进行比较:

git diff master foobar/master

答案 1 :(得分:45)

对你的问题的另一个回复(假设你是主人,已经做了“git fetch origin”让你回复了解远程变化):

1)自创建本地分支以来在远程分支上提交:

git diff HEAD...origin/master

2)我假设“工作副本”是指你的本地分支,其中一些本地提交还没有远程。要查看您在本地分支上的内容的差异,但在远程分支上不存在:

git diff origin/master...HEAD

3)请参阅dbyrne的answer

答案 2 :(得分:19)

这个例子可能对某人有所帮助:

注意“origin”是远程“Github上有什么”的别名 注意“mybranch”是我的分支“我是什么本地”的别名我正在与github同步
   - 如果您没有创建分支名称,则您的分支名称为“master”。但是,我使用不同的名称mybranch来显示分支名称参数的使用位置。


我的远程回购在github上究竟是什么?

$ git remote -v
origin  https://github.com/flipmcf/Playground.git (fetch)
origin  https://github.com/flipmcf/Playground.git (push)

添加“相同代码的其他github存储库” - 我们将其称为fork:

$ git remote add someOtherRepo https://github.com/otherUser/Playground.git

$git remote -v
origin  https://github.com/flipmcf/Playground.git (fetch)
origin  https://github.com/flipmcf/Playground.git (push)
someOtherRepo https://github.com/otherUser/Playground.git (push)
someOtherRepo https://github.com/otherUser/Playground.git (fetch)

确保我们的本地仓库是最新的:

$ git fetch

在本地更改一些内容。让我们说文件./foo/bar.py

$ git status
# On branch mybranch
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   foo/bar.py

查看我未提交的更改

$ git diff mybranch
diff --git a/playground/foo/bar.py b/playground/foo/bar.py
index b4fb1be..516323b 100655
--- a/playground/foo/bar.py
+++ b/playground/foo/bar.py
@@ -1,27 +1,29 @@
- This line is wrong
+ This line is fixed now - yea!
+ And I added this line too.

本地提交。

$ git commit foo/bar.py -m"I changed stuff"
[myfork 9f31ff7] I changed stuff
1 files changed, 2 insertions(+), 1 deletions(-)

现在,我与我的遥控器(在github上)不同

$ git status
# On branch mybranch
# Your branch is ahead of 'origin/mybranch' by 1 commit.
#
nothing to commit (working directory clean)

使用remote - 你的分叉: (这通常使用git diff master origin

完成
$ git diff mybranch origin
diff --git a/playground/foo/bar.py b/playground/foo/bar.py
index 516323b..b4fb1be 100655
--- a/playground/foo/bar.py
+++ b/playground/foo/bar.py
@@ -1,27 +1,29 @@
- This line is wrong
+ This line is fixed now - yea!
+ And I added this line too.

(git push将这些应用于远程)

我的远程分支与远程主分支有何不同?

$ git diff origin/mybranch origin/master

我的本​​地资料与远程主分支有何不同?

$ git diff origin/master

我的东西与其他人的叉子,同一个仓库的主分支有什么不同?

$git diff mybranch someOtherRepo/master
相关问题