Telling Mercurial about the moved files after a major re-organization

12,451

Solution 1

You can use hg mv --after to signify you have already moved the file.

Solution 2

hg addremove will detect renames after-the-fact if the files are 100% similar by default, and the similarity threshold can be overridden with -s.

Also, if using TortoiseHg, thg guess will bring up a dialog where you can use a slider to set the similarity and view the resulting matches between added and deleted files, then select the pairs you want to record as a rename.

Example:

C:\>hg init test
C:\>cd test
C:\test>echo >file1
C:\test>echo ONE>file1
C:\test>echo TWO>file2
C:\test>hg ci -Am init
adding file1
adding file2

C:\test>ren file1 file3
C:\test>ren file2 file4
C:\test>hg st
! file1
! file2
? file3
? file4

C:\test>hg addrem
removing file1
removing file2
adding file3
adding file4
recording removal of file1 as rename to file3 (100% similar)
recording removal of file2 as rename to file4 (100% similar)

C:\test>hg status -C   # -C shows file copies.
A file3
  file1                # file3 copied from file1...
A file4
  file2                # file 4 copied from file2...
R file1
R file2

Solution 3

Use hg addremove. You can't just move files around and expect Mercurial to know about that — if you're moving tracked files, use hg mv.

Share:
12,451
Jesse Atkinson
Author by

Jesse Atkinson

Updated on September 22, 2022

Comments

  • Jesse Atkinson
    Jesse Atkinson almost 2 years

    We recently re-organized a very unorganized site on our server at work. This website is version controlled using Mercurial. We re-organized everything. Thousands of files. Now when I do a hg status it shows a ton of new untracked files represented by a ? and tons of missing files, which are the same files as the untracked ones, represented by a !.

    How do I tell Mercurial that we moved these files? I know I can do it one-by-one, but this isn't an option given that there are thousands of them.