How to remove local (untracked) files from the current Git working tree

前端 未结 30 2111
死守一世寂寞
死守一世寂寞 2020-11-22 00:07

How do you delete untracked local files from your current working tree?

相关标签:
30条回答
  • 2020-11-22 00:57

    If you just want to delete the files listed as untracked by 'git status'

    git stash save -u
    git stash drop "stash@{0}"
    

    I prefer this to 'git clean' because 'git clean' will delete files ignored by git, so your next build will have to rebuild everything and you may lose your IDE settings too.

    0 讨论(0)
  • 2020-11-22 00:58

    git-clean - Remove untracked files from the working tree

    0 讨论(0)
  • 2020-11-22 00:59

    Clean out git repository and all submodules recursively

    The following command will clean out the current git repository and all its submodules recursively:

    (git clean -d -x -f && git submodule foreach --recursive git clean -d -x -f)
    
    0 讨论(0)
  • 2020-11-22 01:00

    This is what I always use:

    git clean -fdx
    

    For a very large project you might want to run it a couple of times.

    0 讨论(0)
  • 2020-11-22 01:00

    git-clean is what you are looking for. It is used to remove untracked files from the working tree.

    0 讨论(0)
  • 2020-11-22 01:00

    We can easily removed local untracked files from the current git working tree by using below git comments.

    git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
    

    Example:

    git reset --hard HEAD
    

    Links :

    1. https://git-scm.com/docs/git-reset
    2. How do I use 'git reset --hard HEAD' to revert to a previous commit?
    3. Reset local repository branch to be just like remote repository HEAD
    4. https://jwiegley.github.io/git-from-the-bottom-up/3-Reset/4-doing-a-hard-reset.html
    0 讨论(0)
提交回复
热议问题