6538.1.32
by Aaron Bentley
Add docs on switch --store. |
1 |
Switch --store |
2 |
============== |
|
3 |
||
4 |
In workflows that a single working tree, like co-located branches, sometimes |
|
6538.1.33
by Aaron Bentley
Tweak docs. |
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. |
|
9 |
||
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. |
|
15 |
||
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 |
|
20 |
between them. |
|
6538.1.32
by Aaron Bentley
Add docs on switch --store. |
21 |
|
22 |
To take an example, first we'd set up a co-located branch:: |
|
23 |
||
24 |
$ bzr init foo |
|
25 |
Created a standalone tree (format: 2a) |
|
26 |
$ cd foo |
|
27 |
$ bzr switch -b foo |
|
28 |
||
29 |
Now create committed and uncommitted changes:: |
|
30 |
||
31 |
$ touch committed |
|
32 |
$ bzr add |
|
33 |
adding committed |
|
34 |
$ bzr commit -m "Add committed" |
|
35 |
Committing to: /home/abentley/sandbox/foo/ |
|
36 |
added committed |
|
37 |
Committed revision 1. |
|
38 |
$ touch uncommitted |
|
39 |
$ bzr add |
|
40 |
adding uncommitted |
|
41 |
$ ls |
|
42 |
committed uncommitted |
|
43 |
||
6538.1.33
by Aaron Bentley
Tweak docs. |
44 |
Now create a new branch using ``--store``. The uncommitted changes are stored |
45 |
in "foo", but the committed changes are retained. |
|
6538.1.32
by Aaron Bentley
Add docs on switch --store. |
46 |
:: |
47 |
||
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 |
|
53 |
committed |
|
54 |
||
55 |
Now, create uncommitted changes in "bar":: |
|
56 |
||
57 |
$ touch uncommitted-bar |
|
58 |
$ bzr add |
|
59 |
adding uncommitted-bar |
|
60 |
||
61 |
Finally, switch back to "foo":: |
|
62 |
||
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/ |
|
67 |
$ ls |
|
68 |
committed uncommitted |
|
69 |
||
70 |
Each branch holds only one set of stored changes. If you try to store a second |
|
6538.1.33
by Aaron Bentley
Tweak docs. |
71 |
set, you get an error. If you use ``--store`` all the time, this can't happen. |
6538.1.32
by Aaron Bentley
Add docs on switch --store. |
72 |
But if you use plain switch, then it won't restore the uncommitted changes |
73 |
already present:: |
|
74 |
||
75 |
$ bzr switch bar |
|
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. |
|
81 |
||
82 |
If you're working in a branch that already has stored changes, you can restore |
|
6538.1.33
by Aaron Bentley
Tweak docs. |
83 |
them with ``bzr switch . --store``:: |
6538.1.32
by Aaron Bentley
Add docs on switch --store. |
84 |
|
85 |
$ bzr shelve --all -m "Uncommitted changes from foo" |
|
86 |
Selected changes: |
|
87 |
-D uncommitted |
|
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/ |
|
92 |
$ ls |
|
93 |
committed uncommitted-bar |