【问题标题】:Why does git status return different results on different branches?为什么 git status 在不同的分支上返回不同的结果?
【发布时间】:2017-12-13 16:23:19
【问题描述】:
$ 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 in 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
$

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

我的问题是:为什么同一命令 git status 有时会告诉我需要提取代码,而有时却不需要? 和我所在的分支有关吗?换分支?什么?

【问题讨论】:

标签: git


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-28
    • 2013-03-10
    • 1970-01-01
    • 2017-04-01
    • 2016-03-31
    • 2014-03-13
    • 2010-10-31
    • 2013-03-13
    相关资源
    最近更新 更多