我尝试在shell中执行以下命令:
git init
echo "test1" > test1.txt
git add test1.txt
git commit -a -m "test1"
echo "test2" >> test1.txt
git branch test
git checkout test
text.txt
现在包含以下内容:
test1
test2
在切换到分支
test
后,所有本地修改都会被合并到master
中。为什么?
我原本以为
git
会因为有本地更改而拒绝切换到test
分支。我原本以为git会要求提交或者将本地更改stash
起来。编辑: 我使用一个bash脚本来执行这些命令,我得到了以下输出:
r@r:/tmp/test$ ./createrepo
Initialized empty Git repository in /tmp/test/.git/
[master (root-commit) 0407f5b] test1
1 file changed, 1 insertion(+)
create mode 100644 test1.txt
M test1.txt
Switched to branch 'test'