简体   繁体   中英

Mercurial diff not working after move/rename

After moving a file into another directory I cannot display the differences between two revisions any more. Eg:

hg init

touch a
hg add a
hg ci -m "Added a"

echo "Bli" >> a
hg ci -m "Bli"
echo "Bla" >> a
hg ci -m "Bla"
echo "Blub" >> a
hg ci -m "Blub"

hg diff -r 0 -r 1 a

Results in:

diff -r 8603b08f5a64 -r 16675581549e a
--- a/a Mon Apr 23 09:03:25 2012 +0000
+++ b/a Mon Apr 23 09:03:25 2012 +0000
@@ -0,0 +1,1 @@
+Bli

which is what I expected. However when I now move the file "a" into a directory "b":

mkdir b
hg mv a b/a
hg ci -m "Moved a into b"
cd b
hg diff -r 0 -r 1 a

this results into nothing (no output at all). I also tried to use the git Giff algo:

hg diff --git -r 0 -r 1 a

Again, there is no output at all. The log is seems to be OK:

hg log --follow a

Results in:

changeset:   4:cb8185829bfd
tag:         tip
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:08:12 2012 +0000
summary:     Moved a into b

changeset:   3:4d1ba89885c3
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:26 2012 +0000
summary:     Blub

changeset:   2:e9126dbb50b2
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:26 2012 +0000
summary:     Bla

changeset:   1:16675581549e
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:25 2012 +0000
summary:     Bli

changeset:   0:8603b08f5a64
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:25 2012 +0000
summary:     Added a

Has someone any idea why the diff is not working after moving a file? Your help is greatly appreciated.

This is difficult or impossible with today's Mercurial. I think the closest you can get is

hg log --follow --patch -r 1 a

where Mercurial will track the copies backwards ( --follow ) before showing the diff ( --patch ).

In general, Mercurial does not track file identities , it only tracks file names . When you lookup information by revision number, Mercurial will first lookup the revision, and then lookup any filenames in that revision. So hg cat -r 0 a will give you the same result as

hg update -r 0
cat a

ie, the result is independent of the current working directory parent.

I think that it's because b/a doesn't exist in revision 1 or revision 0. If you execute the command hg diff -r 0 -r 4 from within the b folder it should produce the expected output.

If you execute hg diff -r 0 -r 1 a from the root of the working copy it should also show the expected output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM