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

发布于 2024-10-19 20:26:30 字数 206 浏览 3 评论 0原文

我已经克隆了一个 github 存储库,并且在本地没有进行任何更改。 Github 存储库随着同一分支上的提交而向前推进。

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

I have cloned a github repository and made no changes locally. Github repository moved forward with commits on the same branch.

  1. How do I find a diff between my local repository and the original github repository?
  2. How do I find a diff between my working copy and the original github repository?
  3. How do I find a diff between my local repository and another github repository of the same project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北城挽邺 2024-10-26 20:26:30

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

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

2) 更新远程存储库的本地副本:

git fetch foobar

Fetch 不会更改您的工作副本。

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

git diff master foobar/master

1) Add any remote repositories you want to compare:

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

2) Update your local copy of a remote:

git fetch foobar

Fetch won't change your working copy.

3) Compare any branch from your local repository to any remote you've added:

git diff master foobar/master
身边 2024-10-26 20:26:30

对您问题的另一个答复(假设您在 master 上并且已经执行了“git fetch origin”以使您存储库了解远程更改):

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

git diff HEAD...origin/master

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

git diff origin/master...HEAD

3) 请参阅 由 dbyrne 回答

Another reply to your questions (assuming you are on master and already did "git fetch origin" to make you repo aware about remote changes):

1) Commits on remote branch since when local branch was created:

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:

git diff origin/master...HEAD

3) See the answer by dbyrne.

许久 2024-10-26 20:26:30

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

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


我在 github 上的远程仓库到底是什么?

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

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

$ 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

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.


What exactly are my remote repos on 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:

$ 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

$ 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)

$ 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 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)

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?

$ git diff origin/master

How does my stuff differ from someone else's fork, master branch of the same repo?

$git diff mybranch someOtherRepo/master
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文