使用过滤器分支删除 Git LFS?(无法将未更改的文件重新添加到索引。)

jnd*_*i75 4 git github git-filter-branch git-lfs git-lfs-migrate

尝试将存储库(包括历史记录)迁移到 Git LFS 之外。

我在测试存储库上运行git lfs migrate export --include="*" --everything此处提到),但它没有按预期工作,并留下了 LFS 指针文件,而不是将它们全部转换为对象。

我尝试了替代方法,遵循。不幸的是它仍然留下了指针文件,所以我将它与this结合起来。

最后,我什至一起运行了所有命令:

git lfs uninstall
git filter-branch -f --prune-empty --tree-filter '
  git lfs fetch
  git lfs checkout
  git lfs ls-files | cut -d " " -f 3 | xargs touch
  git lfs ls-files | cut -d " " -f 3 | xargs git rm --cached
  git rm -f .gitattributes
  git lfs ls-files | cut -d " " -f 3 | xargs git add --force
  git add --renormalize .
' --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)

没用。对于多个文件,给我以下错误,并且过滤的提交具有指针文件而不是对象。

Errors logged to <PATH>
Use `git lfs logs last` to view the log.
Rewrite <COMMIT SHA ####> (2/9) (2 seconds passed, remaining 7 predicted)    
Checking out LFS objects:   0% (0/1), 0 B | 0 B/s           
Checking out LFS objects: 100% (2/2), 3.1 KB | 0 B/s, done
Error updating the git index:
error: picture.png: cannot add to the index - missing --add option?
fatal: Unable to process path picture.png
Run Code Online (Sandbox Code Playgroud)

我尝试仅在提示提交上运行相同的命令,并且似乎touch, rm --cached, add --renormalize .,add --force没有显示任何修改git status。因此,我无法将清理/拉取的对象文件重新添加到新的提交中。

也许这就是问题所在?那么使用filter-branch时如何强制将未更改的文件重新添加到索引中呢?

(使用 Windows 和 git bash。)

Phi*_*ppe 7

  1. 执行 agit lfs migrate export --everything --include .将所有 LFS 指针替换为 git 历史记录中的真实文件。有关更多详细信息,请参阅http://stackoverflow.com/a/57681990/717372

  2. 运行git lfs uninstall以删除 lfs 挂钩。

  3. 并验证是否.gitattributes已删除 lfs 过滤器。

    如果 lfs 过滤器未删除,并且.gitattributes仅 LFS 需要,请使用以下命令删除所有历史记录中的文件:

    git filter-branch -f --prune-empty --tree-filter '
      git rm -f .gitattributes --ignore-unmatch
    ' --tag-name-filter cat -- --all
    
    Run Code Online (Sandbox Code Playgroud)

    否则,如果.gitattributes有非 LFS 行,则通过将上述树过滤器命令替换为git lfs untrack(参考此处此处),仅删除 LFS 过滤器。