Reputation: 80352
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?
Upvotes: 4
Views: 224
Reputation: 318568
-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
Upvotes: 8
Reputation: 2731
Apparently there are two things that we have to do , if we want to commit either modified file or untracked file
first one is "staging " second one is "commit"
The staging is the intermediate stage of any commit journey, of course it is optional.
The staging process is only to prevent the accidental commits . In general before commit ,any new untracked files or modifications in any tracked files need to be staged then after if we type git commit
the files which are staged only be commit .
Simply the main purpose of staging is to prevent the accidental commits . If you use staging process it is handy to discard any changes before commit by using git checkout filename
.
look at this page : http://git-scm.com/about/staging-area
If you really believe that you don't need staging , you can use git commit -a
it will simply commit all current untracked files and modifications in tracked files .
Always it is recommended to go through staging because you can discard any changes that you don't want in current commit . if you use git commit -a
you don't have to use git add filename
for staging
Upvotes: 1
Reputation: 382274
You don't have to.
The -a
option asks git commit
to automatically add all the changes you made to files that are in the repository.
You don't always want that. Especially because sometimes you want to make more than one commit to distinguish between change groups. When you want to choose what to add, you usually add your changes before committing using git add
.
Upvotes: 6
Reputation: 24344
git commit -a
is short hand for:
git add file.txt
git commit file.txt
It is just an easier way of committing new files to the repository. (Files must be "added" before they can be committed)
Upvotes: 1