在Mercurial中如何撤销移动/重命名操作?

7

我执行了hg mv -A oldFile newFile命令,不小心将新文件名搞错了。

我执行了hg revert newFile命令,但现在这个文件不再显示为缺失状态(在移动命令后显示为已删除)。

我该如何撤销操作,回到之前的状态,让新文件显示为未知状态,旧文件显示为缺失状态?

2个回答

8
$ hg st
$ mv a b
$ hg st
! a
? b
$ hg mv -A a b
$ hg st
A b
R a
$ hg revert b
$ hg st
? b
$ ls
a  b

所以hg revert b恢复了旧文件a。现在你需要做的就是hg mv a correct-name


谢谢!没想到它也还原了旧文件的删除。 - Sam Holder
正如最后的 ls 所示,名为“b”的文件仍然存在,因此原始问题尚未完全回答。使用此处所示的技术,文件“b”必须手动删除。当然,在给定的情况下,如果原始的 mv a b 覆盖了 b,则 b 就不存在了。更有理由使用 hg mv - peak

1
这是一个用bash编写的“不可移动”脚本。顶部有一些帮助文本。最重要的一点是,该脚本具有一个选项,强制任何文件删除都必须进行交互式操作。
#!/bin/bash

# Syntax: $0 [OPTION] DEST
#
# This script is mainly intended to undo the effects of: hg move SOURCE DEST
#
# It first determines which files have been added globally (as if by
# hg add), then it runs:

# hg -v revert DEST

# Finally, it removes all the files that had been added,
# and then reverts them as well if possible.
#
# OPTIONS:
# -i :: remove files using rm -i

if [ "$1" = -i ] ; then
    INTERACT=$1
    shift
fi


TODO=()
while read -r f ; do
  TODO+=("$f")
done < <( hg st -an "$@" )

function go {
    hg -v revert "$@"
    for f in "${TODO[@]}" ; do
      rm $INTERACT "$f"
      hg -q files "$f" > /dev/null && hg revert "$f"
    done
}

go

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接