Git:如何检查本地存储库是否是最新的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7938723/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:12:14  来源:igfitidea点击:

Git: How to check if a local repo is up to date?

gitgit-pullgit-fetch

提问by Misha Moroshko

I would like to know if my local repo is up to date (and if not, ideally, I would like to see the changes).

我想知道我的本地存储库是否是最新的(如果不是,理想情况下,我希望看到更改)。

How could I check this without doing git fetchor git pull?

我怎么能不做git fetch或检查这个git pull

回答by Philip Oakley

Try git fetch --dry-runThe manual (git help fetch) says:

试试git fetch --dry-run手册 ( git help fetch) 说:

--dry-run
Show what would be done, without making any changes.

回答by jim smith

git remote show origin

Result:

结果:

HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date) <-------

回答by flowdee

you can use git status -unoto check if your local branch is up-to-date with the origin one.

您可以git status -uno用来检查您的本地分支是否与原始分支保持同步。

回答by Piyush Agarwal

First use git remote update, to bring your remote refs up to date. Then you can do one of several things, such as:

首先使用git remote update, 使您的远程引用保持最新。然后,您可以执行以下几项操作之一,例如:

  1. git status -unowill tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
  2. git show-branch *masterwill show you the commits in all of the branches whose names end in 'master' (eg master and origin/master).
  1. git status -uno会告诉您正在跟踪的分支是在前面、后面还是已经发散。如果它什么也没说,本地和远程是一样的。
  2. git show-branch *master将向您显示名称以“master”结尾的所有分支中的提交(例如 master 和 origin/master)。

If you use -v with git remote update (git remote -v update) you can see which branches got updated, so you don't really need any further commands.

如果您将 -v 与 git remote update (git remote -v update) 一起使用,您可以看到哪些分支已更新,因此您实际上不需要任何其他命令。

回答by Niclas Kirschmeier

Not really - but I don't see how git fetchwould hurt as it won't change any of your local branches.

不是真的 - 但我不知道git fetch会有什么伤害,因为它不会改变你当地的任何分支机构。

回答by Amanuel Nega

Another alternative is to view the status of the remote branch using git show-branch remote/branchto use it as a comparison you could see git show-branch *branchto see the branch in all remotes as well as your repository! check out this answer for more https://stackoverflow.com/a/3278427/2711378

另一种选择是查看远程分支的状态,将 git show-branch remote/branch其用作比较,您可以看到git show-branch *branch所有远程分支以及您的存储库中的分支!查看此答案了解更多https://stackoverflow.com/a/3278427/2711378

回答by user3695833

You'll need to issue two commands:

您需要发出两个命令:

  1. git fetch origin
  2. git status
  1. git 获取来源
  2. 状态

回答by braitsch

You must run git fetchbefore you can compare your local repository against the files on your remote server.

您必须先运行,git fetch然后才能将本地存储库与远程服务器上的文件进行比较。

This command only updates your remote tracking branches and will not affect your worktree until you call git mergeor git pull.

此命令仅更新您的远程跟踪分支,并且在您调用git merge或之前不会影响您的工作树git pull

To see the difference between your local branch and your remote tracking branch once you've fetched you can use git diff or git cherry as explained here.

要在获取后查看本地分支和远程跟踪分支之间的区别,您可以使用git diff 或 git cherry 如此处所述。

回答by J?rg W Mittag

This is impossible without using git fetchor git pull. How can you know whether or not the repository is "up-to-date" without going to the remote repository to see what "up-to-date" even means?

如果不使用git fetch或,这是不可能的git pull。您如何知道存储库是否是“最新的”而不去远程存储库查看“最新”甚至意味着什么?

回答by Don Davis

If you use

如果你使用

git fetch --dry-run -v <link/to/remote/git/repo>

you'll get feedback about whether it is up-to-date. So basically, you just need to add the "verbose" option to the answer given before.

你会得到关于它是否是最新的反馈。所以基本上,您只需要在之前给出的答案中添加“详细”选项即可。