我有一个本地存储库,我不小心提交了一些敏感信息。有人告诉我,从git历史记录中完全删除数据的方法是使用git filter-branch
重写git历史记录。
我有一个庞大的存储库,敏感数据分散在许多目录中。该目录具有某种模式,因此我尝试使用该模式从我的存储库中删除所有敏感信息。
我正在使用的命令如下:
git filter-branch -f --index-filter 'git rm -r --cached --ignore-unmatch src/foo/.bar/.' HEAD
Rewrite 91792897deb2dfe42ea9d8c880cab84960a7ad87 (1/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite f72c448cf2f666e0cc1ec0f9b8cfd0a67a46df0d (2/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 8097470c606c687d7aefc34197ff141e8a9f2a42 (3/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 624f9b4d156b2310c20ff2945644b9447b1ec3f6 (4/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite a3ae4093d90ca1b05fa0a788a5fe4509d1b60c1c (5/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 73ac2bfaf7be8b0ad2daf1187c45588345da9cb9 (6/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 41064096cfe0f8c3e83ac34979baf35aae4a88fe (7/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 8ee64291df85278fcbdff2511d69683ab69d6a56 (8/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite d4126b2f8479ce1443af1684b9713bd50674cd12 (9/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite e731d991ac608ccb4fac4bf46c5d422d38eb1be5 (10/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 65f0b7db70618b338cefd899f02e480c1b59e286 (11/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 20e058029b8f2b8e7483e0cbbf26379d798ea0a5 (12/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite d9d4b427a33f72aae6085595d1241b4308aeb947 (13/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite f6d12207381192ed63edc526eb8b5a04ab3a9aa6 (14/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 0057f1ba3c2bdb370891b662e2c83c6fbf6c7827 (15/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 46c75f6615916c758e2e520e78d34340933299ac (16/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 97c999de1f8910c33f8450b8808f2f9b0510570e (17/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 37ab6c3ab6db8ee357ec349441808d16294517f1 (18/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite e44d4e4218a4cfb8df769dbc78bbd249fe1cf6e7 (19/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
Rewrite 984ce51ba44200d8a20940ae88c1b11394f3741f (20/20) (0 seconds passed, remaining 0 predicted) rm 'src/foo/.bar/metadata.json'
但是当我尝试对以下路径使用模式时:
git filter-branch -f --index-filter 'git rm -r --cached --ignore-unmatch src/*/.bar/.' HEAD
我收到以下警告:
WARNING: Ref 'refs/heads/master' is unchanged
我什至运行了--tree-branch
选项而不是index-filter
,这给了我很大的成功,但是最后我收到了同样的警告,说WARNING: Ref 'refs/heads/master' is unchanged
我还测试了上述命令的许多变体,例如转义*
或使用.*
等,均无济于事。
我想要实现的是从git历史记录中完全删除这些文件和文件夹,同时将它们保留在磁盘上。
我们非常感谢您的帮助。
答案 0 :(得分:0)
每次调用--ignore-unmatch命令时,都需要保护*
字符不被扩展。
test.git $ git filter-branch -f --index-filter 'git ls; git rm -r --cached --ignore-unmatch "*/c/test.txt"'
Rewrite 062465c5e73da1c78d6caccc25a59ca1bdc55ea9 (1/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
a/c/test.txt
Rewrite 978046862ebb59455a05a8f32dda63e6f5f6b498 (2/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
a/c/test.txt
Rewrite 2199c67c1c3fc02782eb53e5b19d112b35fca827 (3/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
a/c/test.txt
rm 'a/c/test.txt'
Ref 'refs/heads/master' was rewritten
test.git $ git filter-branch -f --index-filter 'git ls; git rm -r --cached --ignore-unmatch "*/c/test.txt"'
Rewrite 062465c5e73da1c78d6caccc25a59ca1bdc55ea9 (1/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
Rewrite 978046862ebb59455a05a8f32dda63e6f5f6b498 (2/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
Rewrite fc1da295e426a3535347ec5486c609f27b2aa951 (3/3) (0 seconds passed, remaining 0 predicted) a/b/test.txt
WARNING: Ref 'refs/heads/master' is unchanged