News for hackers. Stuff that matters.
Re:Git Undo by tsm on Thursday August 25, 2016 @10:53AM (#12359447)
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.

Re:Git Undo by komali2 on Thursday August 25, 2016 @11:42AM (#12359920)
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."
Re:Git Undo by agentgt on Thursday August 25, 2016 @11:51AM (#12360002)
You can also use shelve in mercurial. I have never needed to use it on git though because of staging/cheap branches.
Re:Git Undo by krupan on Thursday August 25, 2016 @12:12PM (#12360198)
But why stage when you can just commit? You can use rebase -i to modify that commit later if you need.
Re:Git Undo by minitech on Thursday August 25, 2016 @07:37PM (#12363308)
You might not want to commit all of your changes at once.
Re:Git Undo by krupan on Thursday August 25, 2016 @10:57PM (#12364009)
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).