why i cannot checkout another git branch?

淺唱寂寞╮ 提交于 2019-12-12 09:05:49

问题


$ 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

why i just failed to checkout lab_master branch?

another question: why i cannot compare current file with the file in another branch?

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

回答1:


Git protects you from switching to another branch, because that would override some changes you applied to the file project.properties. You can either throw the changes away by using git checkout -f lab_master or stash them first via git stash (and git stash pop after you checked out the other branch.) If you are sure, you want to keep the changes, you can also simply commit them.




回答2:


You need to either commit your changes or stash them, http://git-scm.com/book/en/Git-Tools-Stashing




回答3:


git diff already uses the -b flag to ignore whitespace. That conflicts with your desire to refer to another branch. For that you need to use 'git diff master..anotherbranch'



来源:https://stackoverflow.com/questions/12596767/why-i-cannot-checkout-another-git-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!