git-fu: Git for the lazy
July 29thGetting started with Git? Git for the lazy is one of the better starting points we’ve seen [via SvN].
There are a million Git cheat-sheets out there, but this one does a pretty good job at picking the more intuitive way of performing a particular task, and showing some sample commands to get it done. The How To Fix Mistakes section is particularly useful, and succint:
Haven't committed yet, but don't want to save the changes?
You can throw them away:
git reset --hard
You can also do it for individual files, but it's a bit different:
git checkout myfile.txt
Forgot something in your last commit? That's easy to fix.
git reset --soft HEAD^
Then write over the last commit:
git commit --amend
Don't make a habit of overwriting/changing history if
it's a public repo you're working with, though.
If I read another post with a laundry list of why git is useful, each bullet linking me to the man page, I’m going to scream. How much time do you think I have?
There is no shortage programmers coming over from Subversion who feel confused and perplexed by all that Git has to offer. My biggest complaint about Git is that there are quite a number of ways to accomplish a specific task, and it’s not always clear that the best practices are.
Tags: git, git checkout, git reset, git revert, man, subversion



July 30th, 2008 at 12:05 am
Umm, I think part of your example is wrong. If you want to change a previous commit, you can do git reset –soft HEAD^ git add filename.c git commit OR as a shorthand (and to preserve the commit message) you can do git add filename.c git commit –amend
But doing the reset and the –amend will mean that you overwrite not your most recent commit, but actually compress your changes, plus the previous commit into TWO commits ago.