我有一个跟踪foo
。现在,既然我心不在焉,我就跑了:
mv foo bar
现在,当我做hg st
时,我得到:
! foo
? bar
我想追溯地解决这个问题 - 好像我做了一个hg mv foo bar
。
现在,我可以编写一个bash脚本来为我做这个 - 但是有什么更好/更简单/更聪明我能做到吗?
使用--after
选项:hg mv --after foo bar
$ hg mv --help
hg rename [OPTION]... SOURCE... DEST
aliases: move, mv
rename files; equivalent of copy + remove
Mark dest as copies of sources; mark sources for deletion. If dest is a
directory, copies are put in that directory. If dest is a file, there can
only be one source.
By default, this command copies the contents of files as they exist in the
working directory. If invoked with -A/--after, the operation is recorded,
but no copying is performed.
This command takes effect at the next commit. To undo a rename before
that, see 'hg revert'.
Returns 0 on success, 1 if errors are encountered.
options ([+] can be repeated):
-A --after record a rename that has already occurred
-f --force forcibly copy over an existing managed file
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
-n --dry-run do not perform actions, just print output
--mq operate on patch repository
(some details hidden, use --verbose to show complete help)
这就是我现在正在做的事情;
#!/bin/bash
function die {
echo "$1" >&2
exit -1
}
(( $# == 2 )) || die "Usage: $0 <moved filename> <original filename>"
[[ -e "$1" ]] || die "Not an existing file: $1"
[[ ! -e "$2" ]] || die "Not a missing file: $2"
hg_st_lines_1=$(hg st "$1" 2>/dev/null | wc -l)
hg_st_lines_2=$(hg st "$2" 2>/dev/null | wc -l)
(( ${hg_st_lines_1} == 1 )) || die "Expected exactly one line in hg status for $1, but got ${hg_st_lines_1}"
(( ${hg_st_lines_2} == 1 )) || die "Expected exactly one line in hg status for $2, but got ${hg_st_lines_2}"
[[ "$(hg st "$1" 2>/dev/null)" == \?* ]] || die "Mercurial does not consider $1 to be an unknown (untracked) file"
[[ "$(hg st "$2" 2>/dev/null)" =~ !.* ]] || die "Mercurial does not consider $2 to be a missing file"
mv $1 $2
hg mv $2 $1