Open nobozo opened 8 years ago
Commenting on my own issue, I did some more research and found on http://stackoverflow.com/questions/20992459/escaping-characters-in-glob-patterns-in-git the statement
"git rm implements its own expansion likely because the files might not be present in the checked-out directory. (Think of the situation where you first rm *~, and then remember that you also want to remove them from git.)"
Is this the reason? If so, is it the only reason?
Here is my understanding of this: Shell filename expansion will be applied based on what exists in your working directory. Git filename expansion will be applied based on what you have in your git index.
so whenever you have a situation where the target of your command might exist in your index but in your file director, git filename expansion is there to save the day.
@nobozo The real reason is git's filename expansion is recursive but shell's not.
For example, you can create a directory that contains several subdirectories and so on.
$ mkdir testA testA/testB testA/testB/testC
$ cd testA
$ touch test1.txt testB/test2.txt testB/testC/test3.txt
$ git init
Now, running git add *.txt
will only add the test1.txt
which is under the testA
directory but in order to add the other txt files in the subdirectories, you must run git add \*.txt
.
So this content is in chapter 2, where we're still not diving super deep into Git internals, so I hesitate to add any kind of content about the differences between Git and Bash wildcard expansion. The reader at this point is just starting to get a hang of Git commands, it's important to not overload them with content that will take them away from the main learning path.
Do we need to elaborate on this somewhere else? Would it have a home in Chapter 10? Or is there just not that much to say about it, and if someone is curious they can do a quick google search?
In 02-git-basics/sections.recording-changes.asc, it says:
"That means you can do things such as:
$ git rm log/*.log
Note the backslash () in front of the *. This is necessary because Git does its own filename expansion in addition to your shell’s filename expansion."
Something should be added here saying why it's necessary for Git to do the filename expansion rather than the shell. For example, let's say the files log/a.log, log/b.log, log/c.log all exist in the log subdirectory. Wouldn't running 'git rm log/*.log' also work? When would normal shell filename expansion not work?