I have not decided if I like the following behavior regarding files / folders that are not under version control.
In particular, it seems strange that un-versioned files seem to follow you when you checkout different branches. It seems like said files should only exist in the branch they were created in.
Can someone please help me understand why / if this is desirable behavior?
For example:
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
EDIT
As it turns out, nothing was changed in the files between the branches in the following first edit. Thanks for the help everyone!
EDIT
It seems that git does not write modification of versioned files when checkouts occur. In the following example, another.txt is not under version control:
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 doesn’t even know that the un-versioned files exist. Technically they aren’t even part of the repository. That is why they are called “un-versioned files.” Git does not modify, delete, store, or keep track of any file unless it is told to.
The classic situation where this is desirable is if your software generates temporary files as part of its build process, or if the compiled executables are left in the same directory as the source code. Obviously, if someone is cloning your repository so they can download your software from you, you would want all those files to be “left behind.” But more importantly, you would not want them cluttering up the version history. It doesn’t matter when these files change, only when the source code changes. So seeing diffs of these files with every commit will only make it harder to find the information you actually want.