简体   繁体   English

本地仓库和原始仓库之间的Git差异

[英]Git diff between local repo and origin repo

If I run these commands: 如果我运行以下命令:

On branch dev
Your branch is ahead of 'origin/dev' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
me:cdt-now me$ git diff
me:cdt-now me$ 

so there is no diff - is that because I need to do 所以没有差异-是因为我需要做

git diff origin/dev

?

I would have thought that git diff would default to 我本以为git diff将默认为

git diff origin/dev

but maybe not. 但也许不是。

By default git diff will look at your current branch and see if there are any differences. 默认情况下, git diff将查看您当前的分支,并查看是否存在任何差异。 So if you made some changes on your current branch that are unstaged, a git diff would show those differences. 因此,如果您在当前分支上进行了一些未git diff更改,则git diff将显示这些差异。 Once you've staged changed ( git add . ), you won't see them unless you specify git diff --cached . 暂存更改( git add . )后,除非指定git diff --cached否则您将看不到它们。

In regards to the behavior of git diff for branches, when you specify another branch, yes it should diff against it. 关于分支的git diff的行为,当您指定另一个分支时,是的,应该对它进行比较。 By default if you have simply branched off of a remote branch, git diff and then specifying a branch should diff your current branch (index is the more appropriate term) and diff against the branch you specify. 默认情况下,如果您只是从远程分支分支出来,则git diff然后指定一个分支应该对您当前的分支(索引是更合适的术语)进行比较,并与您指定的分支进行比较。 However, be aware that your origin/dev is your local representation of the remote branch and you need to make sure that is updated via git fetch . 但是,请注意,您的origin/dev是远程分支的本地表示,并且需要确保通过git fetch对其进行了更新。

Also in your case, it looks like you committed your change. 同样,就您而言,您似乎已做出更改。 A git diff against a branch should show the difference but if this is your local branch and you simply want to see the diff of your last commit again, remember you can also specify HEAD references and go back X number of commits. 对分支的git diff应该显示出差异,但是如果这是您的本地分支,并且您只是想再次查看上一次提交的diff,请记住,您还可以指定HEAD引用并返回X提交数量。 So to go and see the diff of your last commit, you can do git diff HEAD~1 因此,要查看上一次提交的差异,可以执行git diff HEAD~1

More info on git diff . 有关git diff的更多信息。

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

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