繁体   English   中英

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

[英]git diff between cloned and original remote repository

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

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

1)添加要比较的任何远程存储库:

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

2)更新远程的本地副本:

git fetch foobar

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

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

git diff master foobar/master

另一个回答你的问题(假设你是主人并且已经做了“git fetch origin”让你回复了解远程更改):

1)在创建本地分支时提交远程分支:

git diff HEAD...origin/master

2)我假设“工作副本”你的意思是你的本地分支与一些尚未远程的本地提交。 要查看您在本地分支上的内容的差异,但在远程分支上运行时不存在:

git diff origin/master...HEAD

3)请参阅dbyrne的答案

这个例子可能会帮助某人:

注意“ 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)

用远程扩展它 - 你的fork :(这通常用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM