4
In workflows that a single working tree, like co-located branches, sometimes
5
you want to switch while you have uncommitted changes. By default, ``switch``
6
will apply your uncommitted changes to the new branch that you switch to. But
7
often you don't want that. You just want to do some work in the other branch,
8
and eventually return to this branch and work some more.
10
You could run ``bzr shelve --all`` before switching, to store the changes
11
safely. So you have to know that there are uncommitted changes present, and
12
you have to remember to run ``bzr shelve --all``. Then when you switch back to
13
the branch, you need to remember to unshelve the changes, and you need to know
14
what their shelf-id was.
16
Using ``switch --store`` takes care of all of this for you. If there are any
17
uncommitted changes in your tree, it stores them in your branch. It then
18
restores any uncommitted changes that were stored in the branch of your target
19
tree. It's almost like having two working trees and using ``cd`` to switch
22
To take an example, first we'd set up a co-located branch::
25
Created a standalone tree (format: 2a)
29
Now create committed and uncommitted changes::
34
$ bzr commit -m "Add committed"
35
Committing to: /home/abentley/sandbox/foo/
44
Now create a new branch using ``--store``. The uncommitted changes are stored
45
in "foo", but the committed changes are retained.
48
$ bzr switch -b --store bar
49
Uncommitted changes stored in branch "foo".
50
Tree is up to date at revision 1.
51
Switched to branch: /home/abentley/sandbox/foo/
52
abentley@speedy:~/sandbox/foo$ ls
55
Now, create uncommitted changes in "bar"::
57
$ touch uncommitted-bar
59
adding uncommitted-bar
61
Finally, switch back to "foo"::
63
$ bzr switch --store foo
64
Uncommitted changes stored in branch "bar".
65
Tree is up to date at revision 1.
66
Switched to branch: /home/abentley/sandbox/foo/
70
Each branch holds only one set of stored changes. If you try to store a second
71
set, you get an error. If you use ``--store`` all the time, this can't happen.
72
But if you use plain switch, then it won't restore the uncommitted changes
76
Tree is up to date at revision 1.
77
Switched to branch: /home/abentley/sandbox/foo/
78
$ bzr switch --store foo
79
bzr: ERROR: Cannot store uncommitted changes because this branch already
80
stores uncommitted changes.
82
If you're working in a branch that already has stored changes, you can restore
83
them with ``bzr switch . --store``::
85
$ bzr shelve --all -m "Uncommitted changes from foo"
88
Changes shelved with id "1".
89
$ bzr switch . --store
90
Tree is up to date at revision 1.
91
Switched to branch: /home/abentley/sandbox/foo/
93
committed uncommitted-bar