Hacker News new | ask | show | jobs
by 100k 5630 days ago
It is trivial in Mercurial to back out the last commit: hg rollback

I use it all the time to fix typos, add a file I forgot to add, or whatever. Once you push, it is more difficult, but I try not to push my code until it works. I also commit only tested chunks of code, so that is the "unit of work" I aim for.

The equivalent in git is something stupid, I have to look it up every time: git reset --soft HEAD^

That's intuitive!

3 comments

git reset HEAD^ (soft is the default option) is actually pretty intuitive once you're used to git. You're reseting the index to the state it was one commit ago (which is what HEAD^ means. That comes up a lot.)

And if you really forget it often, add this to your ~/.gitconfig:

    [alias]
      rollback = reset HEAD^
Now you can run `git rollback`
I know what HEAD^ (and HEAD^^^^^ or whatever) mean.

The fact that I have to make aliases for commonly used tasks is not a point in git's favor to me.

Do you really uncommit that frequently? I just either amend my commits or keep adding new commits and squash them later.

The point is that you can make just about any workflow with git. The ones that git users less commonly use may not be have easy toplevel commands. People already complain about how many toplevel commands there are with git.

It sounds as though the equivalent mistake would be an accidental push. Good to know that git and mercurial allow you to fix things, in any case.
git push is reversible, too: http://news.ycombinator.com/item?id=2079967 (and note my correction below that simplifies things)
git commit --amend