为什么我不能签出另一个git分支? [英] why i cannot checkout another git branch?

查看:94
本文介绍了为什么我不能签出另一个git分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ 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分支?

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

推荐答案

Git保护您避免切换到另一个分支,因为这会覆盖您对文件project.properties进行的某些更改.您可以使用git checkout -f lab_master放弃更改,也可以先通过git stash(和签出另一个分支的git stash pop)存储它们.如果您确定要保留更改,也可以简单地提交他们.

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.

这篇关于为什么我不能签出另一个git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆