How to automatically remove all .orig files in Mercurial working tree?

后端 未结 12 652
刺人心
刺人心 2020-12-13 08:34

During merges mercurial leaves .orig file for any unresolved file. But after manually resolving problems and marking a file correct it does not delete the .orig file. Can it

相关标签:
12条回答
  • 2020-12-13 09:01

    A command that I use on Linux for cleaning up, saves the need to do a fresh search with find.

    These need to be run from the root directory of the Mercurial project

    hg status | grep ".orig" | cut -d ' ' -f 2- | xargs rm -f

    Or if you want to clear all unknown files.

    hg status | cut -d ' ' -f 2- | xargs rm -f

    0 讨论(0)
  • 2020-12-13 09:06

    I have posted this answer before. But this is the correct place to this answer.

    I made this batch file myself.

    IF "%1%" == "d" (
        del /s *.orig
        del /s *.rej
     ) ELSE ( 
        del /s /p *.rej
        del /s /p *.orig
     )
    

    Help: Save this content as orig.bat

    1. Run orig d to delete all rejects and orig files at once without confirmation
    2. Run orig to delete files with confirmation [Safety mechanism]

    Hope this is helpful.

    0 讨论(0)
  • 2020-12-13 09:09

    I personally use the following from the root of the repo:

    hg purge -p -I **/*.orig | xargs rm -f
    

    It's a little better than using just 'hg purge' or 'hg purge --all' because you can filter out the specific file types you want to include.

    For an explaination:

    • The -p argument prints the list of files to be purged
    • The -I argument whitelist filters the files to include
    • The resulting list is piped to xargs and executed using the rm -f command
    0 讨论(0)
  • 2020-12-13 09:12

    btw. find utility has an action -delete so you can type only:

    find <path-to-files> -name '*.orig' -delete

    0 讨论(0)
  • 2020-12-13 09:13

    you should use the update hook

    update: This is run after an update or merge of the working directory has finished

    0 讨论(0)
  • 2020-12-13 09:13

    I'm working in Powershell and didn't see the answer here:

    # NOTE: be in the root of your repository
    # fetch all .orig files recursively
    $orig = (dir *.orig -recurse) ;
    
    # remove each .orig file
    foreach ($item in $orig) { del $($item.FullName) ; }
    
    # afterwards I make sure to remove the references to the .orig files in the repo
    # then commit & push
    hg addremove ; 
    hg commit -m "remove .orig" ;
    hg push ;
    
    0 讨论(0)
提交回复
热议问题