【发布时间】:2011-02-22 02:17:29
【问题描述】:
我尚未决定是否喜欢以下关于不受版本控制的文件/文件夹的行为。
特别是,当您签出不同的分支时,未版本化的文件似乎会跟随您,这似乎很奇怪。似乎所说的文件应该只存在于创建它们的分支中。
有人可以帮我理解为什么/如果这是可取的行为吗?
例如:
shopkins@shax:~/tmp/test$ ls
hello.txt
shopkins@shax:~/tmp/test$ git branch
-
* master
my_branch
shopkins@shax:~/tmp/test$
shopkins@shax:~/tmp/test$ git checkout my_branch
Switched to branch 'my_branch'
shopkins@shax:~/tmp/test$ mkdir adir
shopkins@shax:~/tmp/test$ touch adir/my_branch.txt
shopkins@shax:~/tmp/test$ git add adir/
shopkins@shax:~/tmp/test$ git commit -a -m "added adir with my_branch.txt"
[my_branch d36964c] added adir with my_branch.txt
0 files changed, 0 insertions(+), 0 deletions(-)
shopkins@shax:~/tmp/test$ git checkout my_branch
Switched to branch 'my_branch'
shopkins@shax:~/tmp/test$ tree
.
|-- adir
| |-- my_branch.txt
| `-- orphan.txt
`-- hello.txt
1 directory, 3 files
create mode 100644 adir/my_branch.txt
shopkins@shax:~/tmp/test$ touch adir/orphan.txt
shopkins@shax:~/tmp/test$ git checkout master
Switched to branch 'master'
shopkins@shax:~/tmp/test$ ls
adir hello.txt
shopkins@shax:~/tmp/test$ tree
.
|-- adir
| `-- orphan.txt
`-- hello.txt
1 directory, 2 files
编辑 事实证明,在以下第一次编辑中,分支之间的文件没有任何变化。感谢大家的帮助!
编辑 似乎 git 在签出时不会写入版本化文件的修改。在以下示例中,another.txt 不受版本控制:
shopkins@shax:~/tmp/test$ ls -l
total 4
drwxr-xr-x 2 shopkins shopkins 4096 2011-02-21 21:49 adir
-rw-r--r-- 1 shopkins shopkins 0 2011-02-21 21:47 another.txt
-rw-r--r-- 1 shopkins shopkins 0 2011-02-21 21:49 hello.txt
shopkins@shax:~/tmp/test$ git checkout my_branch
Switched to branch 'my_branch'
shopkins@shax:~/tmp/test$ ls -l
total 4
drwxr-xr-x 2 shopkins shopkins 4096 2011-02-21 21:49 adir
-rw-r--r-- 1 shopkins shopkins 0 2011-02-21 21:47 another.txt
-rw-r--r-- 1 shopkins shopkins 0 2011-02-21 21:49 hello.txt
shopkins@shax:~/tmp/test$
【问题讨论】:
标签: git git-branch