【发布时间】:2016-01-03 07:42:41
【问题描述】:
我的 git repo 中有不同的分支。我签出一个新分支并应用更改。当我结帐回到我的主分支时,它仍然显示更改。同样,当我在新分支中暂存更改以进行提交,然后签出主分支时,它再次将这些更改显示为已暂存。
为什么即使我切换回我的分支master,我的分支regrid-more-flexible-times 中的更改似乎也会显示(分阶段或非分阶段)?请参阅下面的插图。
$ git branch
* master
regrid-more-flexible-times
regrid-sst
$ git checkout regrid-more-flexible-times
Switched to branch 'regrid-more-flexible-times'
$ git status
# On branch regrid-more-flexible-times
nothing to commit (working directory clean)
$ vim regridworkflow.py
$ git status
# On branch regrid-more-flexible-times
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: regridworkflow.py
#
no changes added to commit (use "git add" and/or "git commit -a")
到目前为止一切顺利。我已经在我的分支regrid-more-flexible-times 中进行了更改。现在我需要返回master 访问代码库而不做任何更改。
$ git checkout master
M mms/src/main/python/regridworkflow.py
Switched to branch 'master'
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: regridworkflow.py
#
no changes added to commit (use "git add" and/or "git commit -a")
嗯?为什么分支master 显示我在分支regrid-more-flexible-times 上所做的未暂存更改?也许只有在我展示它们之后才知道差异?
$ git checkout regrid-more-flexible-times
M mms/src/main/python/regridworkflow.py
Switched to branch 'regrid-more-flexible-times'
$ git add regridworkflow.py
$ git status
# On branch regrid-more-flexible-times
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: regridworkflow.py
#
$ git checkout master
M mms/src/main/python/regridworkflow.py
Switched to branch 'master'
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: regridworkflow.py
#
...为什么分支master 会显示我在分支regrid-more-flexible-times 上进行的更改?
我的目标是能够在分支regrid-more-flexible-times 上进行更改,但能够签出没有这些更改的master 分支。为什么上面的工作流程不这样做,我应该怎么做才能做到这一点?
【问题讨论】:
-
您可以拥有多个工作副本(存储库的两个独立克隆)。或者使用“货架”(不知道具体是什么)。否则,当您切换分支时,您未提交的更改将“与您一起移动”。
标签: git git-branch git-checkout