tags:

views:

71

answers:

3

I'm new to git, coming from SVN world. So far, it seems a lot more useful, but I am still working out the kinks.

Currently, my workflow is like this:

make changes > git add . > git commit > enter log message

What I don't understand is why I seem to have to add all of my files before I commit. They are under version control already? Why does git commit tell me there are no changes added to the commit, but also point out that I have modified files? It says "Changed but not updated:". What does this mean??

Sorry if this is easy, I feel like I am missing some overarching point

+2  A: 

This allows you to separate commits by edits. If you only want to commit these files now, under one commit, and then these next files now, under a second commit, you could do:

git add files_under_one_topic
git commit -m "this is about one thing"

git add files_left_over_to_commit_about_a_completely_different_topic
git commit -m "this is about another thing."
Justin L.
ah so thats it!
Hamy
It goes further even than that. Using `git add -p`, you can stage some changes within a file, but not others.
Novelocrat
whoa. that's really powerful. Good to know that's possible, it will probably come un super handy the few times I need it!
Hamy
+2  A: 

You're not adding files in the sense that you're putting them under git control, but you're adding them to a change list. Some other SCMs such as perforce do this as well. It's handy for building up distinct sets of changes that you aren't ready to commit yet, but you want to commit in separate blocks.

You can commit in a more subversionish way by simply doing git commit -a -- which will commit everything that git knows about that has been changed, just like what svn commit does.

(PS. Since you're coming from the svn world, I'll mention another gotcha that threw me for a loop for a bit -- when you git diff, it will only show you the diff between your current state and what is in the changelist, NOT the difference between your current state and the last commit. If you run git diff immediately after adding all changed files (e.g. git add -u), you'll see an empty diff, even though there are differences to be committed!)

Ether
Ah, thanks for the PS! That is definitely something I have been struggling with!
Hamy
+2  A: 

Git works by using a "staging" area where you prepare what you are going to bundle together as a commit. So, you decided what set of changes you want to commit (e.g. all or a subset), you add them to the staging area, and then you commit what's in the staging area.

When you invoke "git status", it shows you what has been added to the staging area (i.e. "Changes to be committed"), what has been modified among the files git is tracking (i.e. Changed but not updated"), and any new files that you've never added before (i.e. Untracked files).

If you want to just commit stuff that you've changed, but not include newly created files you can use git commit -a "Comment for modified files already under source control."

Derek Greer
Awesome, thanks!
Hamy
Also, note that 'git stage' can be used instead of 'git add', if it helps to keep things straight in your head.
William Pursell
Ah, cool! thanks
Hamy