git - 为什么我不能 checkout 另一个 git 分支?

标签 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

为什么我无法 checkout lab_master 分支?

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

$ 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 - 为什么我不能 checkout 另一个 git 分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12596767/

相关文章:

git - 同一文件中的更改可以拆分为 git 中的不同提交吗?

git - Jenkins 的 npm install 无法安装托管在 bitbucket 上的模块

cvs - 如何在TestComplete中使用CVS?

git workflow branch/clone/stash/--orphan

java - 在Eclipse中添加分支

git - 为什么我 pull 的时候需要一直做 `--set-upstream-to`?

GIT:查找文件列表(例如使用 git ls-files),包括子模块

git - 归咎于不同位置的文件的早期版本

android - 如何让 Android 应用程序检查是否为最新版本(如最新的 Google Play 商店版本)?

version-control - TFS中的跨分支合并?