Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why i cannot checkout another 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

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
like image 958
hugemeow Avatar asked Dec 01 '25 15:12

hugemeow


2 Answers

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.

like image 190
SQiShER Avatar answered Dec 03 '25 13:12

SQiShER


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

like image 32
dutt Avatar answered Dec 03 '25 14:12

dutt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!