Re: tools for easily "uncommitting" parts of a patch I just commited?
From: Jeff King <hidden>
Date: 2016-10-23 01:38:56
On Sun, Oct 23, 2016 at 08:23:01AM +0700, Duy Nguyen wrote:
I hit the same problem sometimes, but in my case sometimes I accidentally do "git add" after "git add -p" and a configuration in "git commit -a" won't help me. I'd prefer we could undo changes in index instead. Something like reflog but for index.
An index write always writes the whole file from scratch, so you really just need to save a copy of the old file. Perhaps something like: rm -f $GIT_DIR/index.old ln $GIT_DIR/index.old $GIT_DIR/index ... and then open $GIT_DIR/index.tmp ... ... and then rename(index.tmp, index) ... could do it cheaply. It's a little more complicated if you want to save a sequence of versions, and eventually would take a lot of space, but presumably a handful of saved indexes would be sufficient. Another option would be an index format that journals, and you could potentially walk back the journal to a point. That seems like a much bigger change (and has weird layering, because deciding when to fold in the journal is usually a performance thing, but obviously this would have user-visible impact about how far back you could undo). -Peff