Search code examples
version-controltortoisehg

Refactoring without losing history - TortoiseHG


I've done some refactoring which resulted in that some of the content of my original file is split into several other files. However I don't want to lose the history of the code that was moved to the other files but I can't seem to find a way to achieve this in Tortoisehg. What would be my best strategy to keep the code history? Is this even possible or do I need to use the original file for history of the code?


Solution

  • You have to use console, hg copy in the middle. Or fix mistake with -A option (did not try)

    Sample for easy case

    >hg log
    2015-01-13 23:48 +0500  fd3ee8f03c54 [tip]
    
            * fileA.txt, fileB.txt: new file.
            * file.txt: deleted file.
            * file.txt, fileA.txt, fileB.txt:
            Refactoring
    
    2015-01-13 23:44 +0500  0c2bb611605a
    
            * .hgignore, file.txt: new file.
            * .hgignore, file.txt:
            Initial state
    

    I.e.: file.txt was commited in initial changeset, later was separated to fileA.txt and fileB.txt and removed

    Before fd3ee8f03c54 I recorded copy for Mercurial with

    >hg cp file.txt fileA.txt
    >hg cp file.txt fileB.txt
    

    and log for single file, used with -f option, now knows about file ancestor

    >hg log -f fileA.txt -T "changeset:\t{rev}:{node|short}\n"
    changeset:      1:fd3ee8f03c54
    changeset:      0:0c2bb611605a
    
    >hg log -f fileB.txt -T "changeset:\t{rev}:{node|short}\n"
    changeset:      1:fd3ee8f03c54
    changeset:      0:0c2bb611605a
    

    or, in TortoiseHG they also can be diff'ed

    Log