ran*_*ein 2 git branch git-checkout git-branch
我知道一般的建议是在git中切换分支之前要有一个干净的状态.(藏匿或公园承诺).我想知道我何时会得到"你有本地更改无法切换分支",我无法遵循逻辑:
我有一个repo,文件名为version.txt,包含文本"1":
git checkout -b new
echo 2 >> version.txt(工作目录不脏,修改文件)
git checkout master(这是怎么回事?我没有阶段\提交我对新的更改)
如果我删除新分支中的文件内容,或者首先暂存文件,也会发生同样的情况.
有人可以帮我理解我什么时候会得到"你有本地更改不能切换分支".?
谢谢,冉
这很简单,如果您对文件进行了更改,则在更改为特定分支时将对其进行修改.
例:
$ git init
Initialized empty Git repository in /tmp/asadfasd/.git/
$ echo 1 > bar
$ git commit -am "commit 1 master"
[master (root-commit) 55da003] commit 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 bar
$ git co -b testbranch
Switched to a new branch 'testbranch'
$ git co master
Switched to branch 'master'
$ echo 2 >> bar
$ git commit -am "commit 2 master"
[master c6dc6d9] commit 2 master
 1 files changed, 1 insertions(+), 0 deletions(-)
$ git co testbranch
Switched to branch 'testbranch'
$ echo 3 >> bar
$ git co master
error: Your local changes to the following files would be overwritten by checkout:
bar
Please, commit your changes or stash them before you can switch branches.
Aborting
如果你在修改文件之前在master上修改testbranch它会起作用,因为文件不会被修改.
另一种方式,如果分支分歧,你修改分歧文件,它将无法正常工作.
| 归档时间: | 
 | 
| 查看次数: | 10872 次 | 
| 最近记录: |