【问题标题】:Remove Git LFS with filter-branch? (Can't re-add unchanged file to index.)使用过滤器分支删除 Git LFS? (无法将未更改的文件重新添加到索引。)
【发布时间】:2020-01-01 10:51:46
【问题描述】:

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

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

我尝试了其他方法,遵循this。不幸的是它仍然留下指针文件,所以我将它与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

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

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

我尝试仅在提示提交上运行相同的命令,似乎 touchrm --cachedadd --renormalize .add --force 没有显示任何对 git status 的修改。所以我无法将清理/拉取的目标文件重新添加到新的提交中。

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

(使用带有 git bash 的 Windows。)

【问题讨论】:

  • 你试过git lfs migrate export吗?见stackoverflow.com/a/57681990/717372
  • @Philippe 这是我尝试的第一件事。不知何故没用...在我的历史记录中留下了指针文件,并且也擦除了 LFS 对象文件夹:(
  • @Philippe 我重读了这篇文章,发现我设置了不同的 --include 选项。完全按照步骤操作后,内容文件成功替换了指针。但它给了我一个新的问题!任何提交的签出都会显示错误“遇到 # 个应该是指针但不是指针的文件”,并且文件显示为已修改,因此 git 强制我将它们添加到新提交中。
  • 我想您收到此消息是因为您仍然安装了 lfs(您必须删除 .gitattributes 文件中的过滤器)
  • 我写了一个稍微好一点的答案;)

标签: git github git-lfs git-filter-branch git-lfs-migrate


【解决方案1】:
  1. 执行git lfs migrate export --everything --include . 将所有 LFS 指针替换为 git 历史记录中的真实文件。更多详情请见http://stackoverflow.com/a/57681990/717372

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

  3. 并确认.gitattributes 已删除 lfs 过滤器。

    如果没有删除 lfs 过滤器,并且如果 LFS 只需要 .gitattributes,请删除所有历史记录中的文件:

    git filter-branch -f --prune-empty --tree-filter '
      git rm -f .gitattributes --ignore-unmatch
    ' --tag-name-filter cat -- --all
    

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

【讨论】:

    猜你喜欢
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 2018-12-21
    • 2023-02-13
    • 2012-08-14
    • 1970-01-01
    • 2019-06-13
    相关资源
    最近更新 更多