I have a problem removing a file from my git repository. In order to demonstrate: In an empty directory perform:
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" Now I would like to remove the file "A.txt" completely from the repository (as if it had never existed):
rm A.txt git log --pretty=oneline --branches -- A.txt git filter-branch --index-filter \ 'git rm --cached --ignore-unmatch A.txt' \ -- --all which gives output:
3ce037a722c2f382a9da42f73577628a639cae25 3. version 43a12da356ad3643657e6bb06259c84f78b82bed 1. version Cannot rewrite branches: You have unstaged changes. Then git status gives:
# 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") What am I doing wrong here? How can I remove the file A.txt completely?