Why should I use "git commit -a" and not just "git commit"?

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

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

I made some changes, tried to commit them using git commit ". This did not seem to make any changes to my local repository (in the local directory .git), and he recommended using" git commit -a "instead.

I am wondering why I need to add "-a" to "git commit" and what is the difference between "stage" and "commit" in git?

+4
source share
5 answers

-a , --all
Tell the team to automatically create files that have been modified and deleted, but new files that you did not tell git about are not affected.

Git has an intermediate area. By default, git commit only captures data added to this staging area. The -a switch captures all uncommitted changes from the working copy itself.

The idea of ​​an intermediate area is that you may not want to make all the changes at once. If in this case you would git add files you want to commit, or if you want it to be even smaller, you would git add -p and highlight only some changes in the file that you need to make.

There is 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

+8
source

You don’t have to.

The -a option asks git commit automatically add all the changes you made to the files in the repository.

You do not always want this. Moreover, sometimes you want to make several assignments in order to distinguish between groups of changes. When you want to choose what to add, you usually add your changes before committing with git add .

+6
source

git commit -a

- short arm for:

 git add file.txt git commit file.txt 

This is just an easier way to write new files to the repository. (Files must be added before they are completed)

+1
source

git -a commit equivalent

 git add . git commit 
+1
source

Obviously, there are two things that we must do if we want to commit either a modified file or an unverified file

the first is "staging", the second is "complete"

An intermediate stage is an intermediate stage of any trip, of course, it is not mandatory. The staging process is only to prevent accidental commission. In general, before committing, any new unprocessed files or modifications in any monitored files must be delivered, and then, if we type git commit , the files that are delivered must be committed.

Just the main purpose of the production is to prevent accidental committing. If you use the staging process, it’s convenient for you to discard any changes before committing with git checkout filename .

look at this page: http://git-scm.com/about/staging-area

If you really think that you do not need a staging, you can use git commit -a , it just captures all the current unplayable files and changes in tracked files.

It is always recommended to go through the stage, because you can undo any changes that are not needed in the current commit. if you use git commit -a you don't need to use git add filename to set

+1
source

All Articles