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

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

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

30条回答
  •  甜味超标
    2020-11-22 00:54

    oh-my-zsh with zsh provides those great aliases via the git plugin. They can be used in bash as well.

    gclean='git clean -fd'
    gpristine='git reset --hard && git clean -dfx'

    • gclean removes untracked directories in addition to untracked files.
    • gpristine hard reset the local changes, remove untracked directories, untracked files and don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.

提交回复
热议问题