在mercurial中撤消移动/重命名操作?

时间:2011-07-11 11:24:05

标签: mercurial move undo

我做了一个hg mv -A oldFile newFile并意外地弄错了新文件。

我做了一个hg revert newFile,但现在显示为缺失的文件(然后在移动命令后删除)现在根本不再显示。

如何撤消该操作并返回到我所处的状态,以便新文件显示为未知且旧文件显示为丢失?

2 个答案:

答案 0 :(得分:7)

$ 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

答案 1 :(得分:0)

这是一个用bash编写的“unmove”脚本。顶部有一些帮助文字。最重要的一点是脚本有一个选项,可以强制任何文件删除以交互方式完成。

#!/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