Undoing commits

You can undo one or more of the most recent commits by using the uncommit operation. This can be useful, for example, if you want to amend your last commit by changing the log message or adjusting the set of changes to include. The uncommit operation moves the branch tip marker one or more revisions back, without changing the working tree, so that you can make any necessary adjustments and commit again.

To see how it works, let's grab a sample branch:

$ bzr branch lp:~bzrbook/bzrbook-examples/uncommit /tmp/uncommit
Branched 6 revisions. 

You can undo the last commit by using the bzr uncommit command without any parameters:

$ cd /tmp/uncommit/
$ bzr uncommit
    6 Janos Gyerik      2013-04-20
      changes just to demonstrate shelving

The above revision(s) will be removed.
Uncommit these revisions? ([y]es, [n]o): yes
You can restore the old tip by running:
  bzr pull . -r revid:janos@axiom-20130420203136-bi9iglm2cevc8tfq

Bazaar shows the short log message of the revisions it is about to uncommit, and prompts for confirmation. To undo the listed revisions, press Y on your keyboard; otherwise, the operation will be aborted.

As a result, the branch tip will be moved backwards to point to the previous revision, while the working tree will be unchanged. The revision pointed to by the branch tip previously is not deleted; you can still access it by its revision ID and restore if necessary by using the hint in the output of the uncommit command.

The changes that were a part of the uncommitted revision will now appear pending, which you can confirm by using the status command:

$ bzr status
renamed:
  images/ => maps/
modified:
  guests.txt
  menu.txt

At this point, you will have various options, such as the following:

  • Commit again but using a different log message, for example, to fix a typo
  • Commit again but using only a subset of all changes, for example, to split a large commit to smaller chunks of changes
  • Revert everything and continue in a completely different direction

You can uncommit more than one revision by specifying a revision parameter by using -r or --revision. All the revisions between the current branch tip and the specified revision will be uncommitted; for example, the command bzr uncommit -r23 will leave the branch at revision 23.

To uncommit using Bazaar Explorer, click on the large Work button in the toolbar and select Uncommit Revisions..., or navigate to Bazaar | Work and select the Uncommit Revisions... option.

Note

Keep in mind that it is strongly discouraged to uncommit revisions in branches that are shared with others, as your collaborators may have already started using the branch before the tip has changed, leading to confusion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.37.10