I did a hg mv -A oldFile newFile
and accidentally got the new file wrong.
I did a hg revert newFile
but now the file which did show as missing (and then as removed after the move command) now no longer shows up at all.
How can I undo that and get back to the state I was in, so that the new file shows as unknown and the old file shows as missing?
$ 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
So hg revert b
restored the old file a
. Now all you have to do is hg mv a correct-name
.
Here's an "unmove" script written in bash. There's some help text at the top. The most important point is that the script has an option that forces any file removal to be done interactively.
#!/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With