简体   繁体   English

git删除除某些文件以外的所有文件

[英]git remove all files except some files

I am trying to remove all files from a git branch except 1 file 我试图从git分支中删除所有文件,除了1个文件

# this removes all files
git rm -rf .
# what should i use to do somthing like that
git rm -rf . --except file1 file2

If you don't have any local changes in the files you want to keep, it's easiest to first remove all files, and then add the ones back you want to keep: 如果您要保留的文件没有任何本地更改,最简单的方法是首先删除所有文件,然后添加要保留的文件:

git rm -rf .
git checkout HEAD -- file1 file2

If you do have local changes, commit or stash them first. 如果您确实有本地更改,请先提交或存储它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM