Git bug?正在显示在其他分支中创建的文件

时间:2014-03-21 05:19:02

标签: git branch

我创建了一个新的回购:

git init

创建了一个新文件并向其添加了文本。

touch hello.txt

创建了一个新分支:

git branch -b halo

创建了一个新文件并向其添加了文本

touch halo.txt

现在从技术上讲,此文件不应显示在分支主文件中。即使我在新分支中跟踪它,它也显示在master中跟踪。我在过去3-4个月内没有使用过git分支,我想知道是否有变化或者是否总是如此?

1 个答案:

答案 0 :(得分:0)

如果您没有将文件提交到分支,则它们不在分支中。如果您刚刚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,这就是我上面使用的内容。