Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have to use "git commit -a" rather than just "git commit"?

Tags:

git

I'm trying to wrap my head around the intricacies of Git.

I pulled down a repository from GitHub using "git clone [url here]".

I made some changes, the tried to commit them with "git commit". This didn't seem to push the changes into my local repository (in local dir ".git), and it recommended that I use "git commit -a" instead.

I'm wondering why do I have to append "-a" to the "git commit", and whats the difference between "stage" and "commit" in git?

like image 568
Contango Avatar asked Dec 03 '22 00:12

Contango


1 Answers

-a, --all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.

Git has a staging area. By default git commit only commits data added to that staging area. The -a switch commits all uncommitted changing from the working copy itself.

The idea of the staging area is that you might not want to commit all changes at once. If that's the case you'd git add the files you want to commit - or if you want it even more fine-grained, you'd git add -p and select only some changes within a file to be commited.

There's a nice explanation plus an image showing how it basically works in the GitHub Git tutorial: http://web.archive.org/web/20130519130755/http://learn.github.com/p/normal.html

like image 86
ThiefMaster Avatar answered Dec 11 '22 15:12

ThiefMaster