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

时间:2017-12-13 16:23:19

标签: git

$ 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 status中的

master告诉我,我的工作树很干净,我的分支与原点(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有时会告诉我我需要提取代码,有时它不会? 是否与我所在的分支有关?改变分支?什么?

1 个答案:

答案 0 :(得分:2)

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

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