gitbashshellbackup

How to make quick backup of untracked files which I want to delete by git clean?


I have a lot of untracked files. I am pretty sure that most of them I can delete, however... you know, backup could be helpful ;)

What you are doing in similar situation?


Solution

  • The following command will create a tar archive in your home directory of all of the untracked (and not ignored) files in your directory:

    git ls-files --others --exclude-standard -z | xargs -0 tar rvf ~/backup-untracked.tar
    

    If you're going to use this technique, check carefully that git ls-files --others --exclude-standard on its own produces the list of files you expect!

    A few notes on this solution might be in order: