這裏是你如何使用git過濾器 - 分支擺脫所有文件的,你不要想:
兩個舊名稱,新名稱重命名中的情況下,獲取您不希望出現在歷史上的文件名列表。例如把它們放在一個名爲toberemoved.txt
運行git過濾分支這樣的文件:
$ git filter-branch --tree-filter "rm -f `cat toberemoved.txt`" branch1 branch2 ...
下面是從git的過濾器分行的相關手冊頁:
--tree-filter <command>
This is the filter for rewriting the tree and its contents. The
argument is evaluated in shell with the working directory set to
the root of the checked out tree. The new tree is then used as-is
(new files are auto-added, disappeared files are auto-removed -
neither .gitignore files nor any other ignore rules HAVE ANY
EFFECT!).
所以,只要確保你想刪除的文件列表都是相對於檢出樹的根。
更新:
若要獲取存在於過去,但不是在當前工作目錄,你可以運行下面的文件列表。請注意,你必須做進一步的努力,使「歷史重命名之前」的重命名的文件:
$ git log --raw |awk '/^:/ { if (! printed[$6]) { print $6; printed[$6] = 1 }}'|while read f;do if [ ! -f $f ]; then echo Deleted: $f;fi;done
即$ 6是受影響在--raw顯示提交的文件的名稱日誌模式。
如果你想知道發生了什麼([D]選擇,[R]註冊,[M]修飾等等)每個提交的每個文件,請參閱--diff-filter選項以git log。
也許其他人可以在如何查找被重新命名的情況下跟蹤文件的舊名稱。
那麼,那些得到了過去重命名的文件?刪除重命名時的歷史記錄或保留重命名(並跟蹤重命名之前的不同文件名) – knittl
好點。我更願意在重命名之前保留歷史記錄,所以需要在其中添加一些額外的文件,這很好。 –