Git删除untracked file的方法
2019年4月29日 / 584次阅读
Git
有的时候,我们会不小心因为写错文件名,或者一些别的原因,在Git仓库中,产生了一些untracked file,有一些untracked file可以通过.gitignore文件来使其隐身,有一些可以通过本文介绍的方法来删除。
xinlin@ubuntu:~/gas$ touch kkk
xinlin@ubuntu:~/gas$ touch aaa
xinlin@ubuntu:~/gas$ touch bbb
xinlin@ubuntu:~/gas$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: README.md
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: gas.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
aaa
bbb
kkk
随便建了3个没用的文件,现在我们来删除:
xinlin@ubuntu:~/gas$ git clean -i
Would remove the following items:
aaa bbb kkk
*** Commands ***
1: clean 2: filter by pattern 3: select by numbers
4: ask each 5: quit 6: help
What now> 3
1: aaa 2: bbb 3: kkk
Select items to delete>> 2
1: aaa * 2: bbb 3: kkk
Select items to delete>>
Would remove the following item:
bbb
*** Commands ***
1: clean 2: filter by pattern 3: select by numbers
4: ask each 5: quit 6: help
What now> c
Removing bbb
用-i这个参数比较安全,以交互式的方式,清晰的告诉你哪些文件会被删除。git clean还有其它参数,参考git help clean。
本文详细介绍了如何使用Git的clean命令以交互式方式安全删除未跟踪文件,避免因误操作产生的杂乱文件干扰仓库管理。
72

被折叠的 条评论
为什么被折叠?



