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

时间:2012-09-26 07:35:03

标签: git version-control git-branch git-diff git-checkout

$ 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

为什么我没有结帐lab_master分支?

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

$ git diff project.properties -b lab_master
fatal: bad flag '-b' used after filename

3 个答案:

答案 0 :(得分:9)

Git可以防止您切换到另一个分支,因为这会覆盖您应用于文件project.properties的某些更改。你可以使用git checkout -f lab_master抛弃更改,或者先通过git stash(以及git stash pop检查其他分支后隐藏更改。)如果您确定,则要保留更改,您也可以简单地提交它们。

答案 1 :(得分:1)

您需要提交更改或存储更改http://git-scm.com/book/en/Git-Tools-Stashing

答案 2 :(得分:0)

git diff已经使用-b标志来忽略空格。 这与你提到另一个分支的愿望相冲突。 为此你需要使用'git diff master..anotherbranch'

相关问题