Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2010-07-03 13:16:40
Size: 1124
Editor: JohanSamyn
Comment:
Revision 5 as of 2010-07-03 16:56:44
Size: 3926
Editor: JohanSamyn
Comment:
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
==== Here's some more detail from Matt about the inner workings. ==== ==== Here's some more detail from Matt about the inner workings (and slightly adapted by experience) ====
Line 15: Line 15:
Backout is basically three steps rolled into one:
 * update -C <rev>
 * revert -r <parent of rev>
 * commit
There's a fourth step that's done automatically if you specify --merge:
 * merge with changeset we were at when we started to backout
And there's a fifth, manual step:
 * commit the result of merging
When step 3 (commit) aborts, you're left with the first two steps completed and you can either `commit` yourself or `update -C` to abandon the process.
Let <startrev> be the revision we're at when we start the backout.<<BR>>
Backout is basically four steps rolled into one:
 1. hg update -C -r <rev-to-backout>
 * hg revert --all -r <parent of rev-to-backout>
 * hg commit
 * hg update -C <startrev>
There's a fifth step that is done automatically if you specify --merge:
 5.#5 hg merge (with <startrev>)
And there's a sixth, manual step:
 6.#6 hg commit (the result of merging)
When step 3 (commit) aborts, you're left with the first two steps completed and you can either `commit` yourself or `update -C` to abandon the process.<<BR>>
Step 4 assures the parents of the committed merge changeset are in the right order. That is : parent1 = <startrev>, and parent2 = <the new backout rev>. See the example below.
Line 27: Line 30:
TODO
Line 29: Line 31:
$ hg init borepo
$ cd borepo
$ echo "line1\nline2" > file.txt
$ hg ci -Am "add file"
}}}
Edit file.txt, so it contains:
{{{
line1
line1a
line2
}}}
Commit and add a few more changesets:
{{{
$ hg ci -m "add line1a"
$ echo line3 >> file.txt
$ hg ci -m "add line3"
$ echo line4 >> file.txt
$ hg ci -m "add line4"
}}}
Which produces the following (somewhat shortened) graph:
{{{
@ changeset: 3:36b1c0649d3e
| tag: tip
| summary: add line4
|
o changeset: 2:2612107e45fe
| summary: add line3
|
o changeset: 1:1f33c361852e
| summary: add line1a
|
o changeset: 0:e3e45b087239
   summary: add file
}}}
Now we backout changeset 1:1f33c361852e.
{{{
$ hg backout -r 1
}}}
The graph is now:
{{{
o changeset: 4:c3daad6d657d
| tag: tip
| parent: 1:1f33c361852e
| summary: Backed out changeset 1f33c361852e
|
| @ changeset: 3:36b1c0649d3e
| | summary: add line4
| |
| o changeset: 2:2612107e45fe
|/ summary: add line3
|
o changeset: 1:1f33c361852e
| summary: add line1a
|
o changeset: 0:e3e45b087239
   summary: add file
}}}
We merge and commit, yielding the final graph:
{{{
@ changeset: 5:236d8d74edf8
|\ tag: tip
| | parent: 3:36b1c0649d3e
| | parent: 4:c3daad6d657d
| | summary: merge backout
| |
| o changeset: 4:c3daad6d657d
| | parent: 1:1f33c361852e
| | summary: Backed out changeset 1f33c361852e
| |
o | changeset: 3:36b1c0649d3e
| | summary: add line4
| |
o | changeset: 2:2612107e45fe
|/ summary: add line3
|
o changeset: 1:1f33c361852e
| summary: add line1a
|
o changeset: 0:e3e45b087239
   summary: add file
}}}
When we try this using the separate steps, and we omit step 4, we get the following graph (note the reversed order of the parents in changeset 5):
{{{
@ changeset: 5:0eeac5ff9c76
|\ tag: tip
| | parent: 4:cbca219e80e1
| | parent: 3:f82e9468d652
| | summary: merge backout
| |
| o changeset: 4:cbca219e80e1
| | parent: 1:0cf85b44002c
| | summary: backout
| |
o | changeset: 3:f82e9468d652
| | summary: add line4
| |
o | changeset: 2:24ceac6b9018
|/ summary: add line3
|
o changeset: 1:0cf85b44002c
| summary: add line1a
|
o changeset: 0:73af1be51d81
   summary: add file
Line 31: Line 137:
See also: [[Revert]] See also: [[Update]], [[Revert]], [[Commit]], [[Merge]]

Backout

hg backout [OPTION]... [-r] REV

Revert the effect of an earlier changeset.

Backout works by applying a changeset that's the opposite of the changeset to be backed out. That new changeset is committed to the repository, and eventually merged.

Help text: http://www.selenic.com/mercurial/hg.1.html#backout

0.1. Here's some more detail from Matt about the inner workings (and slightly adapted by experience)

(see also this email thread)

Let <startrev> be the revision we're at when we start the backout.
Backout is basically four steps rolled into one:

  1. hg update -C -r <rev-to-backout>

  2. hg revert --all -r <parent of rev-to-backout>

  3. hg commit
  4. hg update -C <startrev>

There's a fifth step that is done automatically if you specify --merge:

  1. hg merge (with <startrev>)

And there's a sixth, manual step:

  1. hg commit (the result of merging)

When step 3 (commit) aborts, you're left with the first two steps completed and you can either commit yourself or update -C to abandon the process.
Step 4 assures the parents of the committed merge changeset are in the right order. That is : parent1 = <startrev>, and parent2 = <the new backout rev>. See the example below.

0.2. An example:

$ hg init borepo
$ cd borepo
$ echo "line1\nline2" > file.txt
$ hg ci -Am "add file"

Edit file.txt, so it contains:

line1
line1a
line2

Commit and add a few more changesets:

$ hg ci -m "add line1a"
$ echo line3 >> file.txt
$ hg ci -m "add line3"
$ echo line4 >> file.txt
$ hg ci -m "add line4"

Which produces the following (somewhat shortened) graph:

@  changeset:   3:36b1c0649d3e
|  tag:         tip
|  summary:     add line4
|
o  changeset:   2:2612107e45fe
|  summary:     add line3
|
o  changeset:   1:1f33c361852e
|  summary:     add line1a
|
o  changeset:   0:e3e45b087239
   summary:     add file

Now we backout changeset 1:1f33c361852e.

$ hg backout -r 1

The graph is now:

o  changeset:   4:c3daad6d657d
|  tag:         tip
|  parent:      1:1f33c361852e
|  summary:     Backed out changeset 1f33c361852e
|
| @  changeset:   3:36b1c0649d3e
| |  summary:     add line4
| |
| o  changeset:   2:2612107e45fe
|/   summary:     add line3
|
o  changeset:   1:1f33c361852e
|  summary:     add line1a
|
o  changeset:   0:e3e45b087239
   summary:     add file

We merge and commit, yielding the final graph:

@    changeset:   5:236d8d74edf8
|\   tag:         tip
| |  parent:      3:36b1c0649d3e
| |  parent:      4:c3daad6d657d
| |  summary:     merge backout
| |
| o  changeset:   4:c3daad6d657d
| |  parent:      1:1f33c361852e
| |  summary:     Backed out changeset 1f33c361852e
| |
o |  changeset:   3:36b1c0649d3e
| |  summary:     add line4
| |
o |  changeset:   2:2612107e45fe
|/   summary:     add line3
|
o  changeset:   1:1f33c361852e
|  summary:     add line1a
|
o  changeset:   0:e3e45b087239
   summary:     add file

When we try this using the separate steps, and we omit step 4, we get the following graph (note the reversed order of the parents in changeset 5):

@    changeset:   5:0eeac5ff9c76
|\   tag:         tip
| |  parent:      4:cbca219e80e1
| |  parent:      3:f82e9468d652
| |  summary:     merge backout
| |
| o  changeset:   4:cbca219e80e1
| |  parent:      1:0cf85b44002c
| |  summary:     backout
| |
o |  changeset:   3:f82e9468d652
| |  summary:     add line4
| |
o |  changeset:   2:24ceac6b9018
|/   summary:     add line3
|
o  changeset:   1:0cf85b44002c
|  summary:     add line1a
|
o  changeset:   0:73af1be51d81
   summary:     add file



See also: Update, Revert, Commit, Merge


CategoryCommand

Backout (last edited 2019-11-01 00:19:51 by IanMoody)