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

后端 未结 12 651
刺人心
刺人心 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 08:49

    Personally, I use

    $ rm **/*.orig
    

    if I get tired of the .orig files. This works in Zsh and in Bash 4 after you run shopt -s globstar.

    But if you use another shell or want a built-in solution, then maybe you'll like the purge extension (link updated 2016-08-25). That lets you remove all untracked files with

    $ hg purge
    

    You can remove all untracked and ignored files with

    $ hg purge --all
    

    An advantage of using hg purge is that this will also cleanup directories that become empty after removing the files. The rm command line will just leave the empty directories behind.

    0 讨论(0)
  • 2020-12-13 08:54

    The following will remove .orig files in your entire working copy hierarchy and also works for paths containing spaces:

    find . -name *.orig | while read -d $'\n' file; do rm -v "$file"; done;
    

    I use an alias in my .bash_profile:

    alias clearorig='echo "Removing .orig files..."; find . -name *.orig | \
    while read -d $'\''\n'\'' file; do rm -v "$file"; done;'
    
    0 讨论(0)
  • 2020-12-13 08:56

    I don't like the chosen answer. It doesn't removed everything within all levels of the project. I use this:

    for f in `find . | grep .orig$`; do rm "$f"; done
    

    Works on both Mac and *nix

    0 讨论(0)
  • 2020-12-13 08:57

    If you just want to delete the .orig files, and you happen to be on a Windows computer, the following seems to work well:

    D:\workspace>hg purge -I **/*.orig --all
    

    This will delete all untracked files that end in .orig, but won't delete other untracked files, as the other answers would.

    You can test this before running it by putting the --print flag in as well.

    0 讨论(0)
  • 2020-12-13 08:59

    This is not an automatic way of removing extra files, but it's simple enough to run manually.

    The hg st can show unknown or not tracked files. You can use this output as an argument to the system rm command. Here's an actual example I just performed:

    $ # SHOW ONLY THE CRUFT
    $ hg status --unknown
    ? config/settings.rb.orig
    ? lib/helpers.rb.orig
    ? routes/main.rb.orig
    
    $ # THE CRUFT WITHOUT THE "?" PREFIX
    $ hg status --unknown --no-status
    config/settings.rb.orig
    lib/helpers.rb.orig
    routes/main.rb.orig
    
    $ # SAFELY REMOVE ALL CRUFT
    $ rm -- `hg st -un`
    

    If you have empty directories left behind, the -r and -d flags for rm might help.

    As a bonus, hg status --ignored could be used to cleanup all those ignored temp files as well as swap files from your editor (e.g., Vim).

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

    PowerShell one-liner (recursive):

    Get-ChildItem <path> -Recurse -File -Include *.orig | Remove-Item
    

    For example for the current folder and sub-folders:

    Get-ChildItem . -Recurse -File -Include *.orig | Remove-Item
    
    0 讨论(0)
提交回复
热议问题