我创造了一个新的回购:
git init创建了一个新文件并向其添加了文本。
touch hello.txt创建了一个新分支:
git branch -b halo创建了一个新文件并向其添加了文本。
touch halo.txt现在,从技术上讲,这个文件不应该显示在分支母版中。即使我在新的分支中跟踪这个,它也显示在主人的跟踪中。在过去的3-4个月里,我没有使用过git分支机构,我想知道是否有什么改变了,还是一直都是这样?
发布于 2014-03-21 06:43:44
如果没有将文件提交到分支,则它们不在分支中。如果你只做了git add,那么你就伪造了那些文件。树枝以任何方式追踪它们。如果您切换了一些文件的分支,它们仍然会被分阶段。据我所知,它一直是这样运作的。
原始答案(供参考)
你一定做错什么了。您没有共享所有命令,尤其是提交和如何显示分支的内容。但请考虑这一点:
$ git init /tmp/test1
$ cd /tmp/test1
$ touch hello.txt
$ git add .
$ git commit -m added
[master (root-commit) 12778a0] added
0 files changed
create mode 100644 hello.txt
$ git checkout -b halo
Switched to a new branch 'halo'
$ touch halo.txt
$ git add halo.txt
$ git commit -m 'added halo'
[halo 9a2b380] added halo
0 files changed
create mode 100644 halo.txt
$ git checkout master
Switched to branch 'master'
$ git ls-files
hello.txt
$ git ls-files --with-tree halo
halo.txt
hello.txt一切都按计划进行。这是Git 1.7.10.4
你的命令有一个错误:
git branch -b halo至少在我的版本中,git branch没有-b选项。我想您是指git checkout -b halo,所以这就是我上面所用的。
https://stackoverflow.com/questions/22550785
复制相似问题