我执行了hg mv -A oldFile newFile
命令,不小心将新文件名搞错了。
我执行了hg revert newFile
命令,但现在这个文件不再显示为缺失状态(在移动命令后显示为已删除)。
我该如何撤销操作,回到之前的状态,让新文件显示为未知状态,旧文件显示为缺失状态?
$ 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
。
#!/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
ls
所示,名为“b”的文件仍然存在,因此原始问题尚未完全回答。使用此处所示的技术,文件“b”必须手动删除。当然,在给定的情况下,如果原始的mv a b
覆盖了 b,则 b 就不存在了。更有理由使用hg mv
。 - peak