Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Izzard
10,797 PointsWhat are the Implications of Using the -a Flag When Committing?
Hi All, In the video I believe the -a flag is described as requesting git to commit all changes that can be found between the folder and the repo. I tried the following to get a feel for how this works:
- I added two files to my project folder
- Tried commit with -a flag: git commit -a -m "useful message" Git responds by saying: 'nothing added to commit but untracked files present'.
So then I tried:
- Adding the files to version control: 'git add file-name' for each file
- Then I tried commit without the -a flag This causes both files to be committed.
So the following seems true:
- The -a flag doesn't commit ALL changed files to git unless they are already added to the repo.
- The -a flag isn't required to commit ALL changed files which have been added to the repo.
Would anybody be able to help me understand the exact function of the -a flag? Many Thanks James
2 Answers
jcorum
71,830 PointsHere's a link to the commit section of Git Reference: http://gitref.org/basic/#commit
And here's an excerpt:
git commit -a automatically stage all tracked, modified files before the commit
If you think the git add stage of the workflow is too cumbersome, Git allows you to skip that part with the -a option. This basically tells Git to run git add on any file that is "tracked" - that is, any file that was in your last commit and has been modified. This allows you to do a more Subversion style workflow if you want, simply editing files and then running git commit -a when you want to snapshot everything that has been changed. You still need to run git add to start tracking new files, though, just like Subversion.
James Izzard
10,797 PointsI understand. You still have to add files in the first place, but the -a flag will automatically stage all changed (but already added) files, and commit them. I was not making a distinction between adding new files to the repo and committing updates to files which had already been added. Thankyou
vimer jerry
Full Stack JavaScript Techdegree Student 220 PointsI understand that a new file has to be added so that git can track it. But I don't know what the concept of stage is. Why I need to 'git add' this file again to make it to the staging area before committing it?