[英]Remove a file from a git repository
我從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
?
問題是你正在執行的rm A.txt
。 這是gst報告的未分級變更。 只需在git filter-branch
之后移動這一行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.