我們希望使用Git在我們的Web服務器上部署代碼。因此,我們在生產服務器上初始化了一個裸倉庫。每當我們發佈一個新版本,我們執行一個git結帳到網站的DocumentRoot:Git簽出到外部工作樹並刪除已刪除的文件
git --work-tree=/path/to/webroot/ checkout -f master
在webroot
子目錄,也有未通過的Git跟蹤的幾個文件(緩存文件,用戶上傳文件等等。)。這些必須當然不會被Git在執行結帳時刪除(並且此部分目前工作正常)。
然而,Git的也不會刪除了以前跟蹤,但在此期間已被刪除的文件(例如,他們在發展過程中已被刪除,因爲他們不再需要)。這些文件目前經歷了checkout
進程,導致「死」文件數量穩步增加。有沒有辦法讓Git在執行checkout
時刪除這些文件?重現步驟 -
編輯:
# create dirs and repos
cd /base/path
mkdir repo.git
mkdir target
cd repo.git && git init
# create, add and commit two files
touch test1.txt
touch test2.txt
git add test1.txt test2.txt
git commit -m testcommit
# checkout to target directory
git --work-tree=../target checkout master -f
# target directory now contains both files
# remove one file from file system and git repo, commit
rm test2.txt
git rm test2.txt
git commit -m deletecommit
# checkout to target again
git --work-tree=../target checkout master -f
# target still contains both files
我試圖做同樣的事情,你做了,它適用於我。你能創建一個最簡單的例子並展示如何重現它嗎? – pqnet
當你說文件被刪除時,你的意思是你剛剛從工作樹中刪除它們,還是實際上從git索引中刪除了它們?例如。在這種情況下,你需要後者,通過'git rm'完成 – lemonhead
我從文件系統和存儲庫中刪除了它們。我添加了一個最小的工作示例來說明問題。 – TheWolf