This is the rule for Git beginners: do not use git commit -a
.
This is the rule for advanced Git users: do not use git commit -a
unless:
- you would run
git add -u
before git commit
, and
- you know that the repository is not using a badly written pre-commit script that will misbehave in the presence of
git commit -a
.
From your comment:
@jthill That works, but now it just displays the untracked files when I issue git cam "test commit". Nothing is staged or committed. If I issue the add and commit commands separately, it works fine. Why is that?
The problem here is that git commit -a
is not like git add
followed by git commit
. It's more like git add -u
followed by git commit
(but even then, still not exactly the same). Specifically, git add -u
will only update files that Git already knows about. The u
in -u
stands for update, i.e., don't add any untracked files, but do update all tracked ones as appropriate.
You have an untracked file that you'd like to add. You must use git add
without the -u
option to do this. (Technically there are several other commands that could get you there, but git add
is the one to use.)