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 trial

Development Tools Git Basics Getting Started With Git The Staging Area

Quiz Question: " Now let's commit all the changes we made to the staging area." misleading?

Hello,

I am was trying to complete the quiz for the Staging Area section and ran into this question:" Now let's commit all the changes we made to the staging area." I put:

git commit -a -m "Changes"

And it said that was wrong. My understanding it that we you want to commit all changes in the staging area in multiple files that you use the -a flag. Previous to this question we had added multiple files to the staging area so I am confused.

Thanks!

3 Answers

Kevin Korte
Kevin Korte
28,148 Points

Hey Charlie,

In the particular quiz, it will pass if you do not use the -a flag. At this point, the -a flag doesn't do anything, because we already added README.md and prototype.html to be staged for commit. In the real world, git would have just ignored your -a flag and the commit would have worked. The answer parser here is a bit particular.

The -a flag will commit any files already tracked by git. Before we added README.md and prototype.html, the -a would have only committed the README file as it was the only file being tracked by git.

That's how to use that. It's just a shorthand to add a tracked file to be staged for commit, and commit in one fell swoop. If you wanted to add all files to be staged for commit, whether tracked or untracked, you would use the capital version, or -A to do so.

Hope that helps.

Thanks for taking the time to explain that Kevin! And for getting back to me so quickly. So git commit -m "Changes" will commit all files in the staging area. And since README.md and prototype.html were staged, whatever changes had been made to those files would have been committed in a single commit. Hopefully, I am getting that right.

I am glad the answer parser was particular so I could attempt to get the concept straight. The -A flag sounds like a time saver as well.

Also, for some reason I am putting spaces between paragraphs and they are not showing up in this thread. :)

Cheers

Kevin Korte
Kevin Korte
28,148 Points

Yep, it sounds like you got it. I tend to use the -A flag a lot myself.

Erik Nuber
Erik Nuber
20,629 Points

The problem with the question/answer is that it does not follow the lesson that was taught.

No issue adding in the file using

git add README.md

But then the next question says to commit to it with a comment. According to what the video previous had just taught, the correct answer should be

git commit README.md -m "some comment here"

or

git commit -a -m "some comment here"

Unless I am misunderstanding, taking the file name out should not work at all because it doesn't know what you are commiting. You are supposed to give it a file name to commit a specific file or use -a to commit all changes made to files that the git is watching.

so I'm not sure how

git commit -m "some comment here"

knows what file to commit and, therefore how this is the correct answer.

Ok, this was explained in the next video. To bad the question came before the explanation.

However, I would like to know when using the -m "comment here" why you would use this and put the same text descriptor into multiple files. That seems like a bad practice. I would think you would want to add different descriptive text based on the given specific file.

Kevin Korte
Kevin Korte
28,148 Points

It seems you understand now how git commit -m "message" would know what to commit, correct?

As projects grow, it's perfectly fine to have the same message text for multiple files, especially has projects grow into the 100's of files range, it would be too difficult, and too cumbersome to give each change file it's own message.

Things start to happen in batches, so you might be working on a feature. Let's say you added points to a user just like treehouse has. What files changed, will your html, css, maybe js, and at least a few backend files to fetch the points from the database. It would make sense if all the files were committed under one message, because they all changed together, to bring in one new feature.

The same works for fixing a bug. As we abstract our sites more and more. Having a commit with multiple files in it helps show the relationship of files that has become somewhat abstracted.

Does that help?

Erik Nuber
Erik Nuber
20,629 Points

That makes sense, I am thinking small scale and, everything we have done has been on a fairly small scale of a couple to a handful of pages. Thanks!

Kevin Korte
Kevin Korte
28,148 Points

It has been small scale, which makes it easier to get the concepts. It does get confusing when the large scale concepts don't scale well to small scale, like in this example. Commiting often is always beneficial though, even on big projects, so nothing gets out of hand.