Often in the Git documentation I see something like this:
$ git clone john@githost:simplegit.git
Initialized empty Git repository in /home/john/simplegit/.git/
...
$ cd simplegit/
$ vim lib/simplegit.rb
$ git commit -am 'removed invalid default value'
[master 738ee87] removed invalid default value
1 files changed, 1 insertions(+), 1 deletions(-)
From the documentation:
-a
--allTell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
Pay attention, the lib/simplegit.rb
file wasn't tracked when it was created at once. Whay the -a
option does it tracked? I use Git for Windows and this sample doesn't work when I try to do the similar:
bushm@DESKTOP-ISD2NUH MINGW64 /d/src/sample
$ git init
Initialized empty Git repository in D:/src/sample/.git/
bushm@DESKTOP-ISD2NUH MINGW64 /d/src/sample (master)
$ vim ./text.txt
bushm@DESKTOP-ISD2NUH MINGW64 /d/src/sample (master)
$ git commit -am "First commit"
On branch master
Initial commit
Untracked files:
text.txt
nothing added to commit but untracked files present
bushm@DESKTOP-ISD2NUH MINGW64 /d/src/sample (master)
Update: the part of the documentation that made this confusing was fixed in PR #414 by Matthieu Moy
This is probably just a mistake in the example.
Firstly, you are right. -a
only adds modified and deleted files.
Secondly, when you clone a repo, git doesn't say
Initialized empty Git repository in /home/john/simplegit/.git/
instead it says
Cloning into 'simplegit'...
remote: Counting objects
and some other lines.
Thirdly, in the example
# John's Machine
$ git clone john@githost:simplegit.git
Initialized empty Git repository in /home/john/simplegit/.git/
...
$ cd simplegit/
$ vim lib/simplegit.rb
$ git commit -am 'removed invalid default value'
[master 738ee87] removed invalid default value
1 files changed, 1 insertions(+), 1 deletions(-)
you can see the commit message is 'removed invalid default value'
, which implies that it is modifying a tracked file.
I think the author is just combining some things so he can show a clear example.
It would have been better if he had left out the line Initialized empty Git repository in /home/john/simplegit/.git/