Using shelve to mimic Git's staging area
A. S. Budden
abudden at gmail.com
Tue Sep 27 09:39:45 UTC 2011
On 27 September 2011 10:10, John Arbash Meinel <john at arbash-meinel.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 9/27/2011 11:00 AM, A. S. Budden wrote:
>> Dear all,
>>
>> I've recently been experimenting with bzr shelve. As I understand
>> it, this is intended to be an equivalent to the staging area in
>> git: I can make changes on two separate issues and then commit them
>> separately by moving one set of changes temporarily onto the shelf.
>> I hope I have understood that right.
>>
>> However, I have been unable to work out how to do this when
>> changes are close together in a file. For example, imagine I had a
>> file stuff.c, which "bzr diff" reports as looking like this:
>>
>> === modified file 'Stuff.c' --- Stuff.c 2011-09-22
>> 14:04:20 +0000 +++ Stuff.c 2011-09-27 07:40:16 +0000 @@
>> -42,6 +42,8 @@ * Some random comments preceding the change * that
>> have already been committed. */ +/* I'd like to shelve this change
>> */ +/* But not this one */ void AFunctionThatHasNotChanged(void) {
>> uint8_t variable;
>>
>> With git, I can add one of those too new comment lines to the
>> staging area and commit, then add the other one and commit [1].
>> Obviously this is a rather contrived example, but is there any way
>> to do the equivalent of this with bzr (q)shelve?
>>
>> Thanks,
>>
>> Al
>>
>> [1] In the command line version of git, this is done by editing
>> the patch directly; in "git gui", you can right-click on a line and
>> select either "add hunk to staging area" or "add line to staging
>> area".
>>
>
> If you do "bzr config change_editor=???", and set that to a text
> editor, it will allow you to do "e" to edit the file.
> My change editor is configured to "vim -d".
>
> That gives you a side-by-side of the old value of the file, and the
> new value of the file. You edit the 'new' side until it looks like
> what you want to keep, and then save and exit. And then bzr will leave
> the new value to what you left it, and determine what diff gets
> shelved based on that.
>
> So in the above case you would hit 'e' then delete the "I want to
> shelve this line" case.
Sounds great, thank you. However, I think I must be doing something
wrong. What I did was to run "bzr shelve". I then hit 'e' and gvim
(diff-mode) opened, so I deleted the line "I'd like to shelve this
change" and hit :wqa. I hit 'y' and the change was shelved and I was
left with a working file with just the line "But not this one". I
committed it and everything looked fine. I then did "bzr unshelve"
and was told:
Using changes with id "1".
M Stuff.c
Text conflict in Stuff.c
1 conflicts encountered.
Deleted changes with id "1".
"bzr st" reported:
modified:
Stuff.c
unknown:
Stuff.c.BASE
Stuff.c.OTHER
Stuff.c.THIS
conflicts:
Text conflict in Stuff.c
and bzr diff (ignoring the lines of context) had this to say:
-/* But not this one */
+<<<<<<< TREE
+/* But not this one */
+=======
+<<<<<<<
+=======
+/* I'd like to shelve this change */
+/* But not this one */
+>>>>>>>
+>>>>>>> MERGE-SOURCE
I realise that this can be easily resolved with qconflicts or
whatever, but this does seem to make the process of committing the two
lines separately (which is what I want to achieve) a lot more
difficult.
Am I missing something obvious?
Al
More information about the bazaar
mailing list