Git-LFS 使用新的 .gitattributes 文件进行迁移



我有一个庞大的(32k 提交(git 存储库,我需要在一个分支中重写历史记录以删除一堆大文件,如 .gitattributes 文件所述。这个分支完全是本地的,从来没有打过遥控器(事实上,我们的遥控器因为历史上的文件很大而拒绝了它(。

我知道以下命令将遍历分支的历史记录并删除所有.dll文件:

$ git lfs migrate import --include='*.dll'

但是,由于 .gitattributes 文件存在并且相当广泛,如果有命令可以简单地重播指针化这些文件的工作,如果创建分支时 .gitattributes 文件已经存在?

我会首先在分支的开头插入正确的.gitattributes(例如使用git rebase(:

*--*--x--*--*--*--*--* <- master

*--*--*--*--*--*--a--* <- my/branch
^
commit with updated .gitattributes
# with the commits identified as above, from branch my/branch, run :
$ git rebase -i x
...
# in the opened editor, move commit 'a' at the beginning of the list
# save & close
# you should obtain :
*--*--x--*--*--*--*--* <- master

a'--*--*--*--*--*--*--* <- my/branch (rewritten)
^
rewritten commit

然后:

您可以使用git filter-branch --tree-filter让 git 一个接一个地重播提交,并应用.gitattributes中所述的过滤器:

# first arg is the name of a script to execute on each commit
#   you have nothing to edit : just use 'true' as an action
#   the only action you expect is that git applies the filters
#   when re-staging files for each individual commit
git filter-branch --tree-filter true a'..my/branch

您可能希望添加--prune-empty选项,也可以在重写后删除空提交,例如再次使用git rebase -i

最新更新