【问题标题】:Recovering commits lost after "hg strip" [duplicate]恢复“hg strip”后丢失的提交[重复]
【发布时间】:2023-03-27 12:35:02
【问题描述】:

我有这个 Mercurial 存储库,我在其中保存了一个计数器:

$ echo 1 > count
$ hg add count 
$ hg com -m 'incrementing to 1'
$ echo 2 > count
$ hg com -m 'incrementing to 2'

到目前为止一切顺利,但后来我犯了一个错误:

$ hg com -m 'incrementing to 3'

所以我使用hg strip 来恢复最后一次提交:

$ hg strip --keep -r -2
saved backup bundle to /home/adam/sandbox/count/.hg/strip-backup/bda856a578bf-ff2b025f-backup.hg

我不知道,我犯了另一个更大的错误!我剥离了两个最顶层的提交,我只想剥离最顶层的一个:

$ hg log
changeset:   0:7b5533cf962a
tag:         tip
user:        Adam Victor Nazareth Brandizzi <brandizzi@gmail.com>
date:        Wed May 15 08:00:27 2019 -0300
summary:     incrementing to 1

我如何取回我的提交?

注意:这是我需要使用hg strip 的案例的人为示例。无需浪费时间指出还有其他选择等。

【问题讨论】:

    标签: mercurial


    【解决方案1】:

    我从this message in Mercurial's mailing list 了解到,解决方案非常简单。请注意,当我运行 hg strip --keep -r -2 时,我在输出中得到了这一行:

    saved backup bundle to /home/adam/sandbox/count/.hg/strip-backup/bda856a578bf-ff2b025f-backup.hg
    

    所以,基本上,Mercurial 备份了原始历史!现在我只需要从中拉出来:

    $ hg pull /home/adam/sandbox/count/.hg/strip-backup/bda856a578bf-ff2b025f-backup.hg
    pulling from /home/adam/sandbox/count/.hg/strip-backup/bda856a578bf-ff2b025f-backup.hg
    searching for changes
    adding changesets
    adding manifests
    adding file changes
    added 2 changesets with 2 changes to 1 files
    (run 'hg update' to get a working copy)
    $ hg update
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    

    我的文件恢复到原来的状态了……

    $ cat count 
    66
    

    ...以及我的历史:

    $ hg log
    changeset:   2:fc4d1cc18a4b
    tag:         tip
    user:        Adam Victor Nazareth Brandizzi <brandizzi@gmail.com>
    date:        Wed May 15 08:00:51 2019 -0300
    summary:     incrementing to 3
    
    changeset:   1:bda856a578bf
    user:        Adam Victor Nazareth Brandizzi <brandizzi@gmail.com>
    date:        Wed May 15 08:00:38 2019 -0300
    summary:     incrementing to 2
    
    changeset:   0:7b5533cf962a
    user:        Adam Victor Nazareth Brandizzi <brandizzi@gmail.com>
    date:        Wed May 15 08:00:27 2019 -0300
    summary:     incrementing to 1
    

    现在我可以调用正确的 strip 命令 (hg strip --keep -r -1)。

    如果我们没有备份文件名怎么办?

    您可能丢失了备份文件名(它确实发生在我身上!)但您可以在$YOUR_REPO/.hg/strip-backup 中找到它。如果您有很多备份,只需按时间降序排列即可:

    $ ls -tl .hg/strip-backup/
    total 4
    -rw-rw-r-- 1 adam adam 754 May 15 08:10 bda856a578bf-ff2b025f-backup.hg    
    -rw-rw-r-- 1 adam adam 754 May 15 08:02 02ac79859dd0-0902f53b-backup.hg
    

    最后一个可能就是你想要的那个。

    【讨论】:

      猜你喜欢
      • 2014-10-14
      • 2021-01-11
      • 1970-01-01
      • 2019-06-15
      相关资源
      最近更新 更多