'git revert' Is Not Equivalent To 'svn revert'

I just learned that if you have some changes in your working tree that you want to get rid of, you don't type 'git revert' like you might guess. No, that's what cvs, subversion, mercurial, and bazaar (to name a few) use revert to mean, but not git. With git, revert is used to undo actual commits. Thankfully, you can undo your revert with another 'git revert', I just learned. So let me repeat to be clear, if you have changes to your working files that you want to abandon, DO NOT do this:

git revert HEAD

That will undo your last commit. Do this instead:

git reset --hard HEAD

I'm glad I have that straightened out now. I'm wondering if /etc was really a good place for me to start out playing with git.

UPDATE: Nearly two years later and I'm still getting comments on this. I'm glad I've been able to help people out this way. The discussion in the comments is good, and one thing I'd like to point out is that I now always use and recommend:

git checkout filename

(as recommended by Anonymous and others below) instead of git reset. I think the git stash trick from Nicolas is pretty cool too.

你可能感兴趣的:(SVN)