“git st”为什么说我是最新的,但实际上不是?

huangapple go评论52阅读模式
英文:

Why does `git st` say I am up-to-date, but I am not?

问题

当我在一个仓库中运行 git st 时,我收到以下消息:

Your branch is up to date with 'origin/main'.

但是当我运行 git pull 时,会下载很多提交记录。

但我以为当前的检出/工作目录已经与 origin 保持最新了?

我是否有什么理解错误?

英文:

When I do a git st in a repository I get the message:

Your branch is up to date with 'origin/main'.

But then when I do a git pull a lot of commits are downloaded.

But I thought the current checkout/working directory is up-to-date with origin?

Do I understand something wrong here?

答案1

得分: 3

git status 显示 工作树 的状态,即通过运行 git commit 可以提交的内容,以及在运行 git commit 之前运行 git add 后可以提交的内容。

与任何 远程 状态无关。

查看文档

此 Stack Overflow 帖子此帖子 讨论了如何检查远程更改。

英文:

git status displays the working tree status, i.e.

> what you would commit by running git commit [...] and what you could commit by running git add before running git commit

It has nothing to do with any remote status.

See docs.

This SO post and this one discuss checking for remote changes.

答案2

得分: 2

origin/main 是 Git 所谓的“跟踪分支”。这是另一个存储库(称为远程存储库)中分支的本地副本。关键在于,此本地副本仅通过像 git fetchgit pull 这样的命令进行更新。当您运行 git status 时,它会将您的本地分支 main 与跟踪分支 origin/main 进行比较。它不会查询远程存储库以了解其 main 分支的情况。

英文:

origin/main is what git calls a "tracking branch". This is a local copy of a branch in another repository (called a remote). The key here is that this local copy is only updated with commands like git fetch or git pull. When you run git status, it compares your local branch main with the tracking branch origin/main. It does NOT query the remote to find out what its main branch is like.

答案3

得分: 2

git status 不会联系远程仓库来查看其中的内容,它只会查看本地缓存的内容,即 refs/remotes/origin/main,也叫做 origin/main

要查看仓库是否与远程同步,应使用 git fetchgit pull

英文:

git status does not reach out to the remote repository to see what is there. It only looks at what is already cached locally in refs/remotes/origin/main a.k.a. origin/main.

To see whether the repository is up to date with the remote, the tools to use are git fetch and git pull.

huangapple
  • 本文由 发表于 2023年5月11日 13:40:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76224435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定