Unfuddle STACK Tips & Tricks
Changes Not Staged For Commit in Git
There are 2 types of files detected by a git-status
command:
- Files that have been addded to Git with the
git add
command. These are called tracked files and appear under "Changes not staged for commit". - Files that Git does not know about, simply called untracked files.
Git does not automatically commit all these changes on git commit
. They first need to be marked as ready to be commited, or staged for the next commit - as Git calls it. This is usually done using the git add
command, which works for both tracked and untracked files.
# add+stage one file
$ git add /path/to/file
# add+stage all files, recursively
$ git add .
The git commit
command will only commit the staged files by default, but it can also automatically stage and commit all the tracked files that have been modified with the -a (--all)
option:
# commit previously staged files
$ git commit -m "Commit message"
# commit all files tracked by Git, without the need of git-add
$ git -a -m "Commit message"
For a complete list of all the options check the official Git docs: git-add, git-commit