克隆和原始远程存储库之间的 git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5162800/
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
git diff between cloned and original remote repository
提问by Oleg Proudnikov
I have cloned a github repository and made no changes locally. Github repository moved forward with commits on the same branch.
我已经克隆了一个 github 存储库并且没有在本地进行任何更改。Github 存储库随着在同一分支上的提交而向前推进。
- How do I find a diff between my local repository and the original github repository?
- How do I find a diff between my working copy and the original github repository?
- How do I find a diff between my local repository and another github repository of the same project?
- 如何找到本地存储库和原始 github 存储库之间的差异?
- 如何找到我的工作副本和原始 github 存储库之间的差异?
- 如何找到我的本地存储库和同一项目的另一个 github 存储库之间的差异?
回答by dbyrne
1) Add any remote repositories you want to compare:
1) 添加要比较的任何远程存储库:
git remote add foobar git://github.com/user/foobar.git
2) Update your local copy of a remote:
2) 更新远程的本地副本:
git fetch foobar
Fetch won't change your working copy.
Fetch 不会改变你的工作副本。
3) Compare any branch from your local repository to any remote you've added:
3) 将本地存储库中的任何分支与您添加的任何远程存储库进行比较:
git diff master foobar/master
回答by Ruslan Kabalin
Another reply to your questions (assuming you are on master and already did "git fetch origin" to make you repo aware about remote changes):
对您的问题的另一个回复(假设您在 master 上并且已经执行了“git fetch origin”以使您了解远程更改的回购):
1) Commits on remote branch since when local branch was created:
1) 自创建本地分支以来在远程分支上提交:
git diff HEAD...origin/master
2) I assume by "working copy" you mean your local branch with some local commits that are not yet on remote. To see the differences of what you have on your local branch but that does not exist on remote branch run:
2)我假设“工作副本”是指您的本地分支,其中包含一些尚未远程进行的本地提交。要查看您在本地分支上拥有但在远程分支上不存在的差异,请运行:
git diff origin/master...HEAD
3) See the answerby dbyrne.
3) 见dbyrne的回答。
回答by FlipMcF
This example might help someone:
这个例子可能对某人有所帮助:
Note "origin
" is my alias for remote "What is on Github"
Note "mybranch
" is my alias for my branch "what is local" that I'm syncing with github
--your branch name is 'master' if you didn't create one. However, I'm using the different name mybranch
to show where the branch name parameter is used.
注意“ origin
”是我对远程“Github 上的内容”的别名
注意“ mybranch
”是我的分支“本地是什么”的别名,我正在与 github 同步
——如果你没有创建,你的分支名称是“master”一。但是,我使用不同的名称mybranch
来显示使用分支名称参数的位置。
What exactly are my remote repos on github?
我在 github 上的远程仓库到底是什么?
$ git remote -v
origin https://github.com/flipmcf/Playground.git (fetch)
origin https://github.com/flipmcf/Playground.git (push)
Add the "other github repository of the same code" - we call this a fork:
添加“相同代码的其他 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)
make sure our local repo is up to date:
确保我们的本地仓库是最新的:
$ git fetch
Change some stuff locally. let's say file ./foo/bar.py
在本地更改一些东西。假设文件 ./foo/bar.py
$ git status
# On branch mybranch
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: foo/bar.py
Review my uncommitted changes
查看我未提交的更改
$ 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.
Commit locally.
在本地提交。
$ git commit foo/bar.py -m"I changed stuff"
[myfork 9f31ff7] I changed stuff
1 files changed, 2 insertions(+), 1 deletions(-)
Now, I'm different than my remote (on github)
现在,我不同于我的遥控器(在 github 上)
$ git status
# On branch mybranch
# Your branch is ahead of 'origin/mybranch' by 1 commit.
#
nothing to commit (working directory clean)
Diff this with remote - your fork:
(this is frequently done with git diff master origin
)
将此与远程 - 你的叉子区别开来:(这经常用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 to apply these to remote)
(git push 将这些应用到远程)
How does my remote branch differ from the remote master branch?
我的远程分支与远程主分支有何不同?
$ git diff origin/mybranch origin/master
How does my local stuff differ from the remote master branch?
我的本地内容与远程 master 分支有何不同?
$ git diff origin/master
How does my stuff differ from someone else's fork, master branch of the same repo?
我的东西与其他人的 fork、同一个 repo 的 master 分支有什么不同?
$git diff mybranch someOtherRepo/master