我已经使用git几年了。一些脑细胞死亡,或其他事情正在发生。请耐心等待。
我创建了几个分支。当我更改为一个分支时,例如git checkout example1
,并创建一个文件:touch test
,然后更改为另一个分支,git checkout example2
,test
现在显示在示例2中科。这不是我预期会发生的事情。这是正常的吗?如果不是,可能会导致什么?
答案 0 :(得分:2)
只要您不进行更改,它就会在不同的结帐中保持可见状态。 签出不同的分支不会删除工作目录中的未版本控制的文件。
如果您在example1分支上提交测试文件然后切换到example2,那么一切都应该按预期工作。
答案 1 :(得分:2)
This is normal, expected behaviour. git
doesn't automatically track new files -- you have to tell it to using git add
/git commit
. If you create a new file, don't tell git
to track it, and then switch branches, git
won't complain -- that file isn't doing anything or causing any harm. As long as the filename doesn't conflict with a file that has been committed on the example2
branch, that untracked file will sit there, happy as a clam, until you decide to add it to the repo.
答案 2 :(得分:2)
The file is not being tracked by git. So, if you change branches, git doesn't know with which branch that file should be associated and that's why un-versioned files will be moving with you as you change branches.
To get rid of your problem, either remove that file test or commit it when you are on your desired branch.