Git操作刪除 untracked files


最近使用git 管理項目的時候,編譯過程中出現了很多中間文件,今天發現使用 git clean 命令可以很方便進行清除:

# 刪除 untracked files
git clean -f
 
# 連 untracked 的目錄也一起刪掉
git clean -fd
 
# 連 gitignore 的untrack 文件/目錄也一起刪掉 (慎用,一般這個是用來刪掉編譯出來的 .o之類的文件用的)
git clean -xfd
 
# 在用上述 git clean 前,牆裂建議加上 -n 參數來先看看會刪掉哪些文件,防止重要文件被誤刪
git clean -nxfd
git clean -nf
git clean -nfd
NAME
       git-clean - Remove untracked files from the working tree

SYNOPSIS
       git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...

DESCRIPTION
       Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

       Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for example, be useful to remove all build products.

       If any optional <path>... arguments are given, only those paths are affected.
usage: git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>...

    -q, --quiet           do not print names of files removed
    -n, --dry-run         dry run
    -f, --force           force
    -i, --interactive     interactive cleaning
    -d                    remove whole directories
    -e, --exclude <pattern>
                          add <pattern> to ignore rules
    -x                    remove ignored files, too
    -X                    remove only ignored files

保持更新,轉載請注明出處;更多內容請訪問 cnblogs.com/xuyaowen 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM