I was just processing git course https://try.github.io/levels/1/challenges/1 at code school and was confused by different behaviour of git add '*.txt' and git add *.txt.
String without quoted did not add everything. Same for git rm. Why does it work this way? Or it's just web version specific?
git add -A command will add all modified and untracked files in the entire repository. Whereas git add . will only add modified and untracked files in the current directory and any sub-directories. If you are at the root of the repo, they have the same effect.
Add and commit changesgit add : takes a modified file in your working directory and places the modified version in a staging area. git commit takes everything from the staging area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.
git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit. This means if you git add a deleted file the deletion is staged for commit.
The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .
As mentioned in "Wildcards inside quotes"", globbing doesn't work in either single- or double-quotes.
Fileglobs (e.g.
*.c
) can be given to add all matching files
*.txt
" accross the all worktree (and not just the current folder). You can see examples in t/t4010-diff-pathspec.sh#L53-L56
Commit 8300016 by Junio C Hamano (gitster
) adds another way to prevent file globbing, plus some explanation:
gitcli
: contrast wildcard given to shell and to gitPeople who are not used to working with shell may intellectually understand how the command line argument is massaged by the shell but still have a hard time visualizing the difference between letting the shell expand fileglobs and having Git see the fileglob to use as a pathspec.
Many commands allow wildcards in paths, but you need to protect them from getting globbed by the shell. These two mean different things:
--------------------------------
$ git checkout -- *.c
$ git checkout -- \*.c
--------------------------------
- The former lets your shell expand the fileglob, and you are asking the dot-C files in your working tree to be overwritten with the version in the index.
- The latter passes the
*.c
to Git, and you are asking the paths in the index that match the pattern to be checked out to your working tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With