問題
如何列出洗掉倉庫中任何檔案的所有提交?(不是特定檔案,而是洗掉任何內容的所有提交)。
語境
我們有一個多年歷史的存盤庫,我們計劃將該專案作為開源發布。
我們要檢查是否沒有憑據被過濾到公眾中。
對于跟蹤的檔案,我們可以輕松查看其中的內容,以及過去是否有任何秘密。
但我們想看看“在任何時候,是否有任何檔案可能泄露機密”。
我們只想列出所有被跟蹤和后來洗掉的檔案,以查看這些歷史記錄部分。
uj5u.com熱心網友回復:
列出所有 git 歷史記錄中的所有已洗掉檔案可以通過git log結合--diff-filter. 該日志為您提供了許多選項來顯示有關當時發生的提交的不同資訊。甚至可以獲得一個完全干凈的檔案串列,這些檔案在您的 git 歷史記錄中但已被洗掉。
這些不同的命令將顯示您當前分支上曾經洗掉的所有檔案:
# This one includes the date, commit hash, and Author
git log --diff-filter D
# this one could be a git alias, but includes empty lines
git log --diff-filter D --pretty="format:" --name-only
# this one has the empty lines cleaned up
git log --diff-filter D --pretty="format:" --name-only | sed '/^$/d'
該git reflog命令在查找丟失檔案方面非常強大,因為它只關心 git 操作,而不僅僅是當前分支。它將在所有分支中搜索已洗掉的檔案并報告它們。
# This one includes the commit hash, branch, tag, and commit message
git reflog --diff-filter D
# You might want to at least add the filename
git reflog --diff-filter D --name-only
# this one could be a git alias, but includes empty lines
git reflog --diff-filter D --pretty="format:" --name-only
# this one has the empty lines cleaned up
git reflog --diff-filter D --pretty="format:" --name-only | sed '/^$/d'
uj5u.com熱心網友回復:
git log --diff-filter=D --summary
請參閱在 Git 存盤庫中查找和恢復已洗掉的檔案
如果您不想要所有關于它們被洗掉的提交的資訊,您可以在其中添加一個 grep delete 。
git log --diff-filter=D --summary | grep delete
uj5u.com熱心網友回復:
旁注:
如果您知道要在差異中查找什么 - 例如,如果您知道應該查找包含類似AWS_SECRET_KEY=...or的字串的檔案API_KEY=...,或者如果您知道可能出現在所述檔案中的秘密的價值 - 您可以使用-G選項 :
# will list all commits where the string 'AWS_SECRET_KEY' appears in the diff :
git log --name-status -G "AWS_SECRET_KEY" --all
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496364.html
標籤:混帐 安全 证书 删除文件 git-rewrite-历史
