Not being a git expert, I still sometimes stumble on straightforward things. Recently I did a
git checkout and ran into merge difficulties. One version of a spec had a particular example commented out; another version didn't. I wrestled git for a while, trying to find a way to tell it, "Dude I don't care, pick one file or the other so I can get on with my day." Neither version of the file mattered, because after a day or two more of work, the branch won't need the file at all.
After searching for a simpler solution, I cleaned the file up by hand, did
git add filename, plus
git commit filename, and I was done. Some of the messages I got during the process were confusing, however, and I didn't remember right away that you're supposed to
git add a file that git already knows about.
The first time you use git, people tell you, first you
git add the new files git needs to know about, and then you
git commit those files. It's pretty easy to leap to the conclusion that
git add means "add this file to the list of things git cares about," which makes this use case a little counter-intuitive, or at least less obvious than I would have liked. It's kind of like git has Alzheimer's and you have to introduce it to the same new person twice.
A git tutorial on the GNU Smalltalk blog has part of the answer:
What git add does is to move the current version of the named file to a special staging area, holding files that are ready to be committed
The GitHub blog reports that
git add may soon take on the new name
git stage, to reflect this.
I’m excited that staging files may soon be done via ‘git stage’ rather-than/in-addition-to ‘git add’. This is nice for new users who often have a hard time seeing why you have to keep ‘git add’ing to stage your changes.
The GNU Smalltalk git tutorial's interesting and worth reading. I also stumbled across an awesome feature I hadn't known about:
git add (aka
stage) has an interactive console like IRB or the Rails console. You can also use it for commits. I'm going to give that a whirl and I'll post here if I get any interesting results.