Using shelve to mimic Git's staging area

Eric Siegerman lists08-bzr at davor.org
Wed Sep 28 02:40:42 UTC 2011


On Tue, 2011-09-27 at 12:07 +0100, A. S. Budden wrote:
> I guess I'll have to
> stick with using patches [1],

My approach is:
    # Save the version with the intermingled changes,
    # then get back a clean copy
    cp stuff.c stuff.c.new
    bzr revert stuff.c 

    while stuff.c != stuff.c.new:   # for a sufficiently loose
                                    # definition of equality :-)

        # Use vimdiff to pull across into stuff.c only the bits I
        # want to commit next
        vimdiff stuff.c stuff.c.new

        bzr commit

Sometimes I end up making an unplanned change in one of the
intermediate revisions (e.g. to fix an error or make an
improvement -- or if I simply merged in upstream changes after
stashing away the .new file (not recommended, but sometimes it
can't be helped).  In that case, I copy the change over to
stuff.c.new (again, using vimdiff) so that the .new file always
reflects (my current understanding of) the desired end state.
But I typically set the .new file's buffer to read-only, so that
I don't *accidentally* save changes to it that were meant to be
temporary.

A vim trick (not specific to this scenario, but especially useful
here):
    :w !diff % -
diffs the current buffer's file against the buffer itself, i.e.
"show me this buffer's unsaved changes".  Makes a great sanity
check.

Of course, there's nothing magic about vimdiff; any interactive
diff/merge tool would suit.  I have no idea how to spell that
unsaved-changes trick in emacs, though...

  - Eric




More information about the bazaar mailing list