簡體   English   中英

Git filter-branch 只針對分叉提交

[英]Git filter-branch only on forked commits

我分叉了另一個存儲庫,然后向其中添加了一些文件。 我偶爾會從原始存儲庫中合並更改以保持最新狀態。

我意識到我的 fork 中有一些應該刪除的文件,所以我試圖按照 [1] 從我的 git 存儲庫中刪除一些文件。 源代碼庫有數千個提交,而我有幾百個。

當我執行該命令時,它也會嘗試搜索所有源提交,而不僅僅是我的 fork 提交,這將花費數小時而不是幾分鍾。

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch filename.txt' --prune-empty @

中間有許多來自上游的合並。

master         A---B---C---D---E---F---G (HEAD)
                  /       /
upstream/master  H---I---J---K

[1] https://help.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository

我會建議使用新工具git filter-repo代替 BFG 和git filter-branch

注意:如果您在運行上述命令時收到以下錯誤消息:

Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`

這意味着您必須更新git


參見“ 基於路徑的過濾”:

git filter-repo --path file-to-remove --invert-paths

您可以將它與 ref 過濾結合使用:首先將原始存儲庫(您已經分叉的)的 URL 添加到您的本地存儲庫:

cd /path/to/local/clone/of/my/fork
git remote add upstream /url/original/repo
git fetch upstream

這樣,您可以將過濾限制為僅您的 fork 提交。
這是一個示例,假設您在upstream/master之上添加了提交。

git filter-repo --path file-to-remove --invert-paths \
  --refs upstream/master..<myBranch>

我還沒有看過filter-repo命令,但是您可以將要檢查的提交的確切列表提供給filter-branch-- arg 之后的所有內容都被提供給rev-list filter-branch運行以生成其候選人,例如

git filter-branch --index-filter "$myfilter" -- --first-parent HEAD

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM