为什么git status在不同的分支上返回不同的结果?

问题描述 投票:1回答:1
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
$ git pull
remote: Counting objects: Z746

git statusmaster告诉我,我的工作树很干净,我的树枝与原点(origin/master)是最新的。但是,当我在git pull时,它会删除一大堆我尚未拥有的新代码。

$ git status
On branch development
Your branch is behind 'origin/development' by 243 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
$

git status分支上的development告诉我,我的工作树很干净但是我的分支在原点后面(origin/development)。所以我git pull,它拉下了一大堆我还没有的新代码。

我的问题是:为什么同样的命令git status有时会告诉我我需要提取代码,有时它不会?是否与我所在的分支有关?改变分支?什么?

git
1个回答
2
投票

在第一种情况下,您本地结帐master分支的内容将与存储在origin/master中的最新已知版本的远程跟踪分支进行比较。由于在此阶段没有执行任何网络操作,并且您的结帐似乎是最新报告的内容。现在,一旦发出git pull,就命令它联系远程存储库,如果有任何新的更改,请将它们应用到本地副本。

在第二种情况下,你检查了分支development,切换到另一个分支,发出git pull(只更新检出分支)或git fetch(不更新当前分支)。现在,当你发出git status git时,你会发现你的本地结账是在远程对手的后面。发布git pull会将本地分支更新为远程仓库中的最新版本。

© www.soinside.com 2019 - 2024. All rights reserved.