Git rm several files?

2019-03-18 00:30发布

How do I easily remove several files without manually typing the full paths of all of them to git rm? I have plenty of modified files I'd like to keep so removing all modified is not possible either.

And also it is possible to revert the changes of several files without manually typing git checkout -- /path/to/file?

标签: git git-rm
9条回答
相关推荐>>
2楼-- · 2019-03-18 01:08

You can give wildcards to git rm.

e.g.

git rm *.c

Or you can just write down the names of all the files in another file, say filesToRemove.txt:

path/to/file.c
path/to/another/file2.c
path/to/some/other/file3.c

You can automate this:

find . -name '*.c' > filesToRemove.txt

Open the file and review the names (to make sure it's alright).

Then:

cat filesToRemove.txt | xargs git rm

Or:

for i in `cat filesToRemove.txt`; do git rm $i; done

Check the manpage for xargs for more options (esp. if it's too many files).

查看更多
等我变得足够好
3楼-- · 2019-03-18 01:10

You can simply use:

git add -u
查看更多
劳资没心,怎么记你
4楼-- · 2019-03-18 01:12

For removing multiple files at once, you might want to checkout the answer here

You can delete the files that you don't want and run this command: git rm $(git ls-files --deleted)

查看更多
Deceive 欺骗
5楼-- · 2019-03-18 01:17

Just delete them using any other method (Explorer, whatever), then run git add -A. As to reverting several files, you can also checkout a directory.

查看更多
The star\"
6楼-- · 2019-03-18 01:17

You simply use

find . -name '*.DS_Store' | xargs git rm

to remove many files match the wildcards.

查看更多
一纸荒年 Trace。
7楼-- · 2019-03-18 01:18

You could also check out Cygwin, as it provides much of the Unix/Linux/*BSD functionality on Windows. Cygwin includes a Bash shell and find(1), among other tools mentioned above. (I usually have 2-4 Cygwin mintty terminals up at one time on Windows 7 because I find Cygwin that handy.)

查看更多
登录 后发表回答