为什么我不能结帐另一个git分支?

hug*_*eow 2 git version-control git-diff git-checkout git-branch

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/lab_master
  remotes/origin/master

$ git checkout lab_master
error: Your local changes to the following files would be overwritten by checkou                                                                                                                           t:
        **project.properties**
Please, commit your changes or stash them before you can switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud)

为什么我只是没有结账lab_master分支?

另一个问题:为什么我无法将当前文件与另一个分支中的文件进行比较?

$ git diff project.properties -b lab_master
fatal: bad flag '-b' used after filename
Run Code Online (Sandbox Code Playgroud)

SQi*_*hER 9

Git会保护您不要切换到另一个分支,因为这会覆盖您应用于文件的某些更改project.properties.您可以通过使用git checkout -f lab_master或首先通过git stash(以及git stash pop在签出其他分支之后)将更改丢弃.如果您确定要保留更改,您也可以简单地提交它们.

  • @hugemeow:是的,它可以 (3认同)