这很简单,如果您对文件进行了更改,如果您更改到特定分支,则该文件将被修改。
例子:
$ 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
如果您在修改文件之前将 testbranch 重新设置在 master 上,它会起作用,因为文件不会被修改。
另一种说法是,如果分支是分歧的,并且您修改分歧的文件,它将无法工作。