<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Switch –store — Bazaar 2.6.0 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.6.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/bzr.ico"/> <link rel="top" title="Bazaar 2.6.0 documentation" href="../index.html" /> <link rel="up" title="Bazaar User Guide" href="index.html" /> <link rel="next" title="Shelving Changes" href="shelving_changes.html" /> <link rel="prev" title="Pseudo merging" href="adv_merging.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="shelving_changes.html" title="Shelving Changes" accesskey="N">next</a></li> <li class="right" > <a href="adv_merging.html" title="Pseudo merging" accesskey="P">previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li><a href="../index.html">Table of Contents (2.6.0)</a> »</li> <li><a href="index.html" accesskey="U">Bazaar User Guide</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="switch-store"> <h1>Switch –store<a class="headerlink" href="#switch-store" title="Permalink to this headline">¶</a></h1> <p>In workflows that a single working tree, like co-located branches, sometimes you want to switch while you have uncommitted changes. By default, <tt class="docutils literal"><span class="pre">switch</span></tt> will apply your uncommitted changes to the new branch that you switch to. But often you don’t want that. You just want to do some work in the other branch, and eventually return to this branch and work some more.</p> <p>You could run <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">shelve</span> <span class="pre">--all</span></tt> before switching, to store the changes safely. So you have to know that there are uncommitted changes present, and you have to remember to run <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">shelve</span> <span class="pre">--all</span></tt>. Then when you switch back to the branch, you need to remember to unshelve the changes, and you need to know what their shelf-id was.</p> <p>Using <tt class="docutils literal"><span class="pre">switch</span> <span class="pre">--store</span></tt> takes care of all of this for you. If there are any uncommitted changes in your tree, it stores them in your branch. It then restores any uncommitted changes that were stored in the branch of your target tree. It’s almost like having two working trees and using <tt class="docutils literal"><span class="pre">cd</span></tt> to switch between them.</p> <p>To take an example, first we’d set up a co-located branch:</p> <div class="highlight-python"><div class="highlight"><pre>$ bzr init foo Created a standalone tree (format: 2a) $ cd foo $ bzr switch -b foo </pre></div> </div> <p>Now create committed and uncommitted changes:</p> <div class="highlight-python"><div class="highlight"><pre>$ touch committed $ bzr add adding committed $ bzr commit -m "Add committed" Committing to: /home/abentley/sandbox/foo/ added committed Committed revision 1. $ touch uncommitted $ bzr add adding uncommitted $ ls committed uncommitted </pre></div> </div> <p>Now create a new branch using <tt class="docutils literal"><span class="pre">--store</span></tt>. The uncommitted changes are stored in “foo”, but the committed changes are retained.</p> <div class="highlight-python"><div class="highlight"><pre>$ bzr switch -b --store bar Uncommitted changes stored in branch "foo". Tree is up to date at revision 1. Switched to branch: /home/abentley/sandbox/foo/ abentley@speedy:~/sandbox/foo$ ls committed </pre></div> </div> <p>Now, create uncommitted changes in “bar”:</p> <div class="highlight-python"><div class="highlight"><pre>$ touch uncommitted-bar $ bzr add adding uncommitted-bar </pre></div> </div> <p>Finally, switch back to “foo”:</p> <div class="highlight-python"><div class="highlight"><pre>$ bzr switch --store foo Uncommitted changes stored in branch "bar". Tree is up to date at revision 1. Switched to branch: /home/abentley/sandbox/foo/ $ ls committed uncommitted </pre></div> </div> <p>Each branch holds only one set of stored changes. If you try to store a second set, you get an error. If you use <tt class="docutils literal"><span class="pre">--store</span></tt> all the time, this can’t happen. But if you use plain switch, then it won’t restore the uncommitted changes already present:</p> <div class="highlight-python"><div class="highlight"><pre>$ bzr switch bar Tree is up to date at revision 1. Switched to branch: /home/abentley/sandbox/foo/ $ bzr switch --store foo bzr: ERROR: Cannot store uncommitted changes because this branch already stores uncommitted changes. </pre></div> </div> <p>If you’re working in a branch that already has stored changes, you can restore them with <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">switch</span> <span class="pre">.</span> <span class="pre">--store</span></tt>:</p> <div class="highlight-python"><div class="highlight"><pre>$ bzr shelve --all -m "Uncommitted changes from foo" Selected changes: -D uncommitted Changes shelved with id "1". $ bzr switch . --store Tree is up to date at revision 1. Switched to branch: /home/abentley/sandbox/foo/ $ ls committed uncommitted-bar </pre></div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="adv_merging.html" title="previous chapter">Pseudo merging</a></p> <h4>Next topic</h4> <p class="topless"><a href="shelving_changes.html" title="next chapter">Shelving Changes</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/user-guide/switch_store.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="shelving_changes.html" title="Shelving Changes" >next</a></li> <li class="right" > <a href="adv_merging.html" title="Pseudo merging" >previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li><a href="../index.html">Table of Contents (2.6.0)</a> »</li> <li><a href="index.html" >Bazaar User Guide</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2011 Canonical Ltd. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3. </div> </body> </html>