从我的 git 存储库中删除文件时遇到问题。为了演示: 在一个空目录中执行:
git init
echo "A" > A.txt
echo "B" > B.txt
git add .
git commit -a -m "1. version"
echo "C" > C.txt
git add .
git commit -a -m "2. version"
echo "A" >> A.txt
git add .
git commit -a -m "3. version"
现在我想从存储库中完全删除文件“A.txt”(就好像它从未存在过一样):
rm A.txt
git log --pretty=oneline --branches -- A.txt
git filter-branch --index-filter \
'git rm --cached --ignore-unmatch A.txt' \
-- --all
这给出了输出:
3ce037a722c2f382a9da42f73577628a639cae25 3. version
43a12da356ad3643657e6bb06259c84f78b82bed 1. version
Cannot rewrite branches: You have unstaged changes.
然后git status
给出:
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: A.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
我在这里做错了什么?如何完全删除文件A.txt
?