在使用Git的过程中,我们会希望删除仓库(比如GitHub)的目录或文件。

  1. 删除directory文件夹

     git rm directory/
    

    这里要加对应的斜杠

  2. 删除file文件

     git rm <file>
    
  3. 强制删除,添加-rf

     git rm -rf directory/
     git rm -rf file
    
  4. 其他补充说明:

     -n, --dry-run         dry run
     -q, --quiet           do not list removed files
     --cached              only remove from the index
     -f, --force           override the up-to-date check
     -r                    allow recursive removal
     --ignore-unmatch      exit with a zero status even if nothing matched
     --pathspec-from-file <file>
                           read pathspec from file
     --pathspec-file-nul   with --pathspec-from-file, pathspec elements are separated with NUL character
    

参考链接:如何在git中删除指定的文件和目录