使用filter-branch命令删除Git LFS?(无法将未更改的文件重新添加到索引。)

4

尝试将包括历史记录的 repo 从 Git LFS 迁移出来。

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

我尝试了另一种方法,遵循这里的指导。不幸的是,它仍然留下了指针文件,因此我将其与此处的方法相结合。

最终,我甚至将所有命令一起运行:

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

我尝试在仅针对最新提交的命令中运行相同的命令,看起来使用git status未显示任何修改的touchrm --cachedadd --renormalize .add --force命令。所以我无法将已清理/拉取的对象文件重新添加到新提交中。

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

(使用Windows和git bash。)


你试过git lfs migrate export吗?参考https://dev59.com/4FYM5IYBdhLWcg3wjAkR#57681990 - Philippe
@Philippe 那是我尝试的第一件事。不知何故没有起作用...在我的历史记录中留下了指针文件,并清除了LFS对象文件夹 :( - jndi75
@Philippe 我重新阅读了帖子,发现我设置了不同的 --include 选项。按照步骤执行后,内容文件成功替换了指针。但是它给我带来了一个新问题!检出任何提交都会显示错误“遇到 # 个应该是指针但实际上不是的文件”,并且这些文件会出现为修改状态,因此 git 强制我将它们添加到一个新的提交中。 - jndi75
我想您收到这条消息是因为您仍然安装了lfs(您必须删除.gitattributes文件中的过滤器)。 - Philippe
@Philippe 没错。然后,我进行了一个虚拟提交,接着使用 git rm -f .gitattributes 进行树过滤。效果很好。(这让我感到惊讶,因为 git lfs migrate export 已经在 .gitattributes 中添加了一行来取消 lfs 过滤器,但是也许我指定的文件不正确。) 谢谢!如果您想添加您的答案,我会接受它 (或者我可以添加它)。 :) - jndi75
1
我写了一个稍微更好的答案 ;) - Philippe
1个回答

7
  1. Do a git lfs migrate export --everything --include . to replace all the LFS pointers by the real files in the git history. For more details, see https://dev59.com/4FYM5IYBdhLWcg3wjAkR#57681990

  2. Run git lfs uninstall to remove lfs hooks.

  3. And verify that the .gitattributes has the lfs filters removed.

    If the lfs filters were not removed, and if .gitattributes was only needed for LFS, delete the file in all of history with:

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

    Otherwise if .gitattributes has non-LFS lines, remove only the LFS filters by replacing the above tree-filter command with git lfs untrack (reference here and here).


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接