我克隆了一个 Github 存储库,但没有在本地进行更改。该存储库在同一分支上向前推进了提交。
- 如何找出本地存储库和原始 Github 存储库之间的差异?
- 如何找出工作副本和原始 Github 存储库之间的差异?
- 如何找出本地存储库和同一项目的另一个 Github 存储库之间的差异?
我克隆了一个 Github 存储库,但没有在本地进行更改。该存储库在同一分支上向前推进了提交。
1)添加任何您想要比较的远程仓库:
git remote add foobar git://github.com/user/foobar.git
2) 更新您所拥有的远程代码库的本地副本:
git fetch foobar
获取操作不会改变您的工作副本。
3)将本地仓库中的任何分支与您添加的任何远程分支进行比较:
git diff master foobar/master
git remote update
而不是fetch
(第2个) - 它将更新所有设置为跟踪远程分支的分支,但不会合并任何更改; 或者使用git pull
。 - Timo回答你的问题(假设你在主分支上,并且已经执行了“git fetch origin”命令使你的本地仓库获取远程更改):
1)自从本地分支创建以来,远程分支的提交:
git diff HEAD...origin/master
2) 我假设你所说的“工作副本”是指你的本地分支,其中包含一些尚未推送到远程的本地提交。要查看本地分支上存在但在远程分支上不存在的差异,请运行:
git diff origin/master...HEAD
3) 查看dbyrne的回答。
HEAD..origin/master
语法!我们一直遇到 origin/HEAD 不存在的错误,这个解决了问题。 - Dan Bechardgit diff HEAD...origin/master
什么都不返回时,这是什么意思? - Mona Jalal这个例子可能对某些人有所帮助:
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)
将此与远程仓库进行比较 - 您的分支:
(通常使用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
我的东西与同一仓库的其他人的衍生版本(fork)或主分支(master branch)有何不同?
$git diff mybranch someOtherRepo/master
git fetch
。 - FlipMcF