git 使用 git ls-tree -r master --name-only 查看已经跟踪的文件,使用 git rm --cached filename 删除已经跟踪的文件。
git 查看和删除已经跟踪的操作示例
初始化git仓库
mkdir -p ~/gittest
cd ~/gittest
git init .
echo "hello" > a.txt
git add .
git commit -m 'test'
查看已经跟踪的文件
git ls-tree -r master
100644 blob ce013625030ba8dba906f756967f9e9ca394464a a.txt
删除已跟踪的文件
git rm --cached a.txt
rm 'a.txt'
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
a.txt
执行删除后需要执行提交
git commit -m 'delete a.txt'
[master 96ac39e] delete a.txt
1 file changed, 1 deletion(-)
delete mode 100644 a.txt
再次查看已经跟踪的文件
git ls-tree -r master
# 结果是空的
git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
a.txt