Hacker News new | ask | show | jobs
by tsm 3588 days ago
I had a recent epiphany about staging, which is that it really starts making sense if you stage as you go.

Let's say you want to write small feature X, and it truly makes sense for X to be a single commit. But doing X involves changing around both Y and Z. Git makes the following workflow easy:

* Fiddle around until you get Y working how you want it

* Stage it

* Fiddle around trying to get Z to work. Try something experimental. Nope, that's not you want it. `git checkout .` Try again.

You don't have to worry about only blasting away the failed Z attempt while preserving Y—since Y is staged, it's easy to keep around.

2 comments

Technically the same metaphor can be used for "commit" if we assume you stage the one thing and commit that one thing. Now look through the same workflow again but replace "stage" with "stage it and commit it."
You can also use shelve in mercurial. I have never needed to use it on git though because of staging/cheap branches.
But why stage when you can just commit? You can use rebase -i to modify that commit later if you need.
You might not want to commit all of your changes at once.
commit can be followed by a file name. Or there is commit --interactive or commit --patch to choose what to commit (or git add versions of those).