Mercurial > hgbook
comparison en/ch08-undo.xml @ 808:557552d4699f
Add IDs to paragraphs.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 21 Apr 2009 23:51:47 -0700 |
parents | 7226e5e750a6 |
children | 1a0a78e197c3 |
comparison
equal
deleted
inserted
replaced
807:7226e5e750a6 | 808:557552d4699f |
---|---|
194 &interaction.daily.revert.status; | 194 &interaction.daily.revert.status; |
195 | 195 |
196 <tip> | 196 <tip> |
197 <title>Be careful with <filename>.orig</filename> files</title> | 197 <title>Be careful with <filename>.orig</filename> files</title> |
198 | 198 |
199 <para>It's extremely unlikely that you are either using | 199 <para id="x_6b8">It's extremely unlikely that you are either using |
200 Mercurial to manage files with <filename>.orig</filename> | 200 Mercurial to manage files with <filename>.orig</filename> |
201 extensions or that you even care about the contents of such | 201 extensions or that you even care about the contents of such |
202 files. Just in case, though, it's useful to remember that | 202 files. Just in case, though, it's useful to remember that |
203 <command role="hg-cmd">hg revert</command> will | 203 <command role="hg-cmd">hg revert</command> will |
204 unconditionally overwrite an existing file with a | 204 unconditionally overwrite an existing file with a |
394 | 394 |
395 <para id="x_103">The result is that you end up <quote>back where you | 395 <para id="x_103">The result is that you end up <quote>back where you |
396 were</quote>, only with some extra history that undoes the | 396 were</quote>, only with some extra history that undoes the |
397 effect of the changeset you wanted to back out.</para> | 397 effect of the changeset you wanted to back out.</para> |
398 | 398 |
399 <para>You might wonder why Mercurial does not commit the result | 399 <para id="x_6b9">You might wonder why Mercurial does not commit the result |
400 of the merge that it performed. The reason lies in Mercurial | 400 of the merge that it performed. The reason lies in Mercurial |
401 behaving conservatively: a merge naturally has more scope for | 401 behaving conservatively: a merge naturally has more scope for |
402 error than simply undoing the effect of the tip changeset, | 402 error than simply undoing the effect of the tip changeset, |
403 so your work will be safest if you first inspect (and test!) | 403 so your work will be safest if you first inspect (and test!) |
404 the result of the merge, <emphasis>then</emphasis> commit | 404 the result of the merge, <emphasis>then</emphasis> commit |
632 changesets intact.</para> | 632 changesets intact.</para> |
633 | 633 |
634 <sect2> | 634 <sect2> |
635 <title>Backing out a merge</title> | 635 <title>Backing out a merge</title> |
636 | 636 |
637 <para>Since merges are often complicated, it is not unheard of | 637 <para id="x_6ba">Since merges are often complicated, it is not unheard of |
638 for a merge to be mangled badly, but committed erroneously. | 638 for a merge to be mangled badly, but committed erroneously. |
639 Mercurial provides an important safeguard against bad merges | 639 Mercurial provides an important safeguard against bad merges |
640 by refusing to commit unresolved files, but human ingenuity | 640 by refusing to commit unresolved files, but human ingenuity |
641 guarantees that it is still possible to mess a merge up and | 641 guarantees that it is still possible to mess a merge up and |
642 commit it.</para> | 642 commit it.</para> |
643 | 643 |
644 <para>Given a bad merge that has been committed, usually the | 644 <para id="x_6bb">Given a bad merge that has been committed, usually the |
645 best way to approach it is to simply try to repair the damage | 645 best way to approach it is to simply try to repair the damage |
646 by hand. A complete disaster that cannot be easily fixed up | 646 by hand. A complete disaster that cannot be easily fixed up |
647 by hand ought to be very rare, but the <command | 647 by hand ought to be very rare, but the <command |
648 role="hg-cmd">hg backout</command> command may help in | 648 role="hg-cmd">hg backout</command> command may help in |
649 making the cleanup easier. It offers a <option | 649 making the cleanup easier. It offers a <option |
657 <imageobject><imagedata fileref="figs/bad-merge-1.png"/></imageobject> | 657 <imageobject><imagedata fileref="figs/bad-merge-1.png"/></imageobject> |
658 <textobject><phrase>XXX add text</phrase></textobject> | 658 <textobject><phrase>XXX add text</phrase></textobject> |
659 </mediaobject> | 659 </mediaobject> |
660 </figure> | 660 </figure> |
661 | 661 |
662 <para>Suppose we have a revision graph like that in <xref | 662 <para id="x_6bc">Suppose we have a revision graph like that in <xref |
663 linkend="fig:undo:bad-merge-1"/>. What we'd like is to | 663 linkend="fig:undo:bad-merge-1"/>. What we'd like is to |
664 <emphasis>redo</emphasis> the merge of revisions 2 and | 664 <emphasis>redo</emphasis> the merge of revisions 2 and |
665 3.</para> | 665 3.</para> |
666 | 666 |
667 <para>One way to do so would be as follows.</para> | 667 <para id="x_6bd">One way to do so would be as follows.</para> |
668 | 668 |
669 <orderedlist> | 669 <orderedlist> |
670 <listitem> | 670 <listitem> |
671 <para>Call <command role="hg-cmd">hg backout --rev=4 | 671 <para id="x_6be">Call <command role="hg-cmd">hg backout --rev=4 |
672 --parent=2</command>. This tells <command | 672 --parent=2</command>. This tells <command |
673 role="hg-cmd">hg backout</command> to back out revision | 673 role="hg-cmd">hg backout</command> to back out revision |
674 4, which is the bad merge, and to when deciding which | 674 4, which is the bad merge, and to when deciding which |
675 revision to prefer, to choose parent 2, one of the parents | 675 revision to prefer, to choose parent 2, one of the parents |
676 of the merge. The effect can be seen in <xref | 676 of the merge. The effect can be seen in <xref |
683 </mediaobject> | 683 </mediaobject> |
684 </figure> | 684 </figure> |
685 </listitem> | 685 </listitem> |
686 | 686 |
687 <listitem> | 687 <listitem> |
688 <para>Call <command role="hg-cmd">hg backout --rev=4 | 688 <para id="x_6bf">Call <command role="hg-cmd">hg backout --rev=4 |
689 --parent=3</command>. This tells <command | 689 --parent=3</command>. This tells <command |
690 role="hg-cmd">hg backout</command> to back out revision | 690 role="hg-cmd">hg backout</command> to back out revision |
691 4 again, but this time to choose parent 3, the other | 691 4 again, but this time to choose parent 3, the other |
692 parent of the merge. The result is visible in <xref | 692 parent of the merge. The result is visible in <xref |
693 linkend="fig:undo:bad-merge-3"/>, in which the repository | 693 linkend="fig:undo:bad-merge-3"/>, in which the repository |
701 </mediaobject> | 701 </mediaobject> |
702 </figure> | 702 </figure> |
703 </listitem> | 703 </listitem> |
704 | 704 |
705 <listitem> | 705 <listitem> |
706 <para>Redo the bad merge by merging the two backout heads, | 706 <para id="x_6c0">Redo the bad merge by merging the two backout heads, |
707 which reduces the number of heads in the repository to | 707 which reduces the number of heads in the repository to |
708 two, as can be seen in <xref | 708 two, as can be seen in <xref |
709 linkend="fig:undo:bad-merge-4"/>.</para> | 709 linkend="fig:undo:bad-merge-4"/>.</para> |
710 <figure id="fig:undo:bad-merge-4"> | 710 <figure id="fig:undo:bad-merge-4"> |
711 <title>Merging the backouts</title> | 711 <title>Merging the backouts</title> |
715 </mediaobject> | 715 </mediaobject> |
716 </figure> | 716 </figure> |
717 </listitem> | 717 </listitem> |
718 | 718 |
719 <listitem> | 719 <listitem> |
720 <para>Merge with the commit that was made after the bad | 720 <para id="x_6c1">Merge with the commit that was made after the bad |
721 merge, as shown in <xref | 721 merge, as shown in <xref |
722 linkend="fig:undo:bad-merge-5"/>.</para> | 722 linkend="fig:undo:bad-merge-5"/>.</para> |
723 <figure id="fig:undo:bad-merge-5"> | 723 <figure id="fig:undo:bad-merge-5"> |
724 <title>Merging the backouts</title> | 724 <title>Merging the backouts</title> |
725 <mediaobject> | 725 <mediaobject> |
759 </sect2> | 759 </sect2> |
760 | 760 |
761 <sect2> | 761 <sect2> |
762 <title>What to do about sensitive changes that escape</title> | 762 <title>What to do about sensitive changes that escape</title> |
763 | 763 |
764 <para>Even a carefully run project can suffer an unfortunate | 764 <para id="x_6c2">Even a carefully run project can suffer an unfortunate |
765 event such as the committing and uncontrolled propagation of a | 765 event such as the committing and uncontrolled propagation of a |
766 file that contains important passwords.</para> | 766 file that contains important passwords.</para> |
767 | 767 |
768 <para>If something like this happens to you, and the information | 768 <para id="x_6c3">If something like this happens to you, and the information |
769 that gets accidentally propagated is truly sensitive, your | 769 that gets accidentally propagated is truly sensitive, your |
770 first step should be to mitigate the effect of the leak | 770 first step should be to mitigate the effect of the leak |
771 without trying to control the leak itself. If you are not 100% | 771 without trying to control the leak itself. If you are not 100% |
772 certain that you know exactly who could have seen the changes, | 772 certain that you know exactly who could have seen the changes, |
773 you should immediately change passwords, cancel credit cards, | 773 you should immediately change passwords, cancel credit cards, |
774 or find some other way to make sure that the information that | 774 or find some other way to make sure that the information that |
775 has leaked is no longer useful. In other words, assume that | 775 has leaked is no longer useful. In other words, assume that |
776 the change has propagated far and wide, and that there's | 776 the change has propagated far and wide, and that there's |
777 nothing more you can do.</para> | 777 nothing more you can do.</para> |
778 | 778 |
779 <para>You might hope that there would be mechanisms you could | 779 <para id="x_6c4">You might hope that there would be mechanisms you could |
780 use to either figure out who has seen a change or to erase the | 780 use to either figure out who has seen a change or to erase the |
781 change permanently everywhere, but there are good reasons why | 781 change permanently everywhere, but there are good reasons why |
782 these are not possible.</para> | 782 these are not possible.</para> |
783 | 783 |
784 <para>Mercurial does not provide an audit trail of who has | 784 <para id="x_6c5">Mercurial does not provide an audit trail of who has |
785 pulled changes from a repository, because it is usually either | 785 pulled changes from a repository, because it is usually either |
786 impossible to record such information or trivial to spoof it. | 786 impossible to record such information or trivial to spoof it. |
787 In a multi-user or networked environment, you should thus be | 787 In a multi-user or networked environment, you should thus be |
788 extremely skeptical of yourself if you think that you have | 788 extremely skeptical of yourself if you think that you have |
789 identified every place that a sensitive changeset has | 789 identified every place that a sensitive changeset has |
791 bundles by email, have their backup software save data | 791 bundles by email, have their backup software save data |
792 offsite, carry repositories on USB sticks, and find other | 792 offsite, carry repositories on USB sticks, and find other |
793 completely innocent ways to confound your attempts to track | 793 completely innocent ways to confound your attempts to track |
794 down every copy of a problematic change.</para> | 794 down every copy of a problematic change.</para> |
795 | 795 |
796 <para>Mercurial also does not provide a way to make a file or | 796 <para id="x_6c6">Mercurial also does not provide a way to make a file or |
797 changeset completely disappear from history, because there is | 797 changeset completely disappear from history, because there is |
798 no way to enforce its disappearance; someone could easily | 798 no way to enforce its disappearance; someone could easily |
799 modify their copy of Mercurial to ignore such directives. In | 799 modify their copy of Mercurial to ignore such directives. In |
800 addition, even if Mercurial provided such a capability, | 800 addition, even if Mercurial provided such a capability, |
801 someone who simply hadn't pulled a <quote>make this file | 801 someone who simply hadn't pulled a <quote>make this file |