如何清理回购,如果阶段性文件标记为修改?

git reset --hard

我得到

Encountered 7 file(s) that should have been pointers, but weren't:

运行git clean -fdx也没有帮助。


当前回答

下面的进程将添加一个提交,将所有应该是lfs指针的二进制文件替换为lfs指针。

Clean working copy completely. Together with the force add below this prevents any files getting added or removed due to .gitignore patterns. git clean -dfx git reset --hard git checkout -- . Add remove for everything to staging area. Working copy will not be touched. git rm --cached -r . Readd all files from working copy again. This will basically undo the previous command but will reevaluate lfs filters. Use -f to ignore .gitignore. All files present were previously checked in and should get added again. git add -f . You staging area now should only contain the binary files that previously raised the 'should have been pointers' error. git commit -m "moved files to lfs"

其他回答

自从git lfs 2.5.0以来,有一个新的命令可以让这变得更容易(docs):

git lfs migrate import --no-rewrite "broken file.jpg" "another broken file.png" ...

这将文件“迁移”到git lfs中,根据.gitattributes应该在lfs中,但目前没有(这就是出现错误消息的原因)。

——no-rewrite阻止git将此应用于旧的提交,而是创建一个新的提交。

使用-m "commitmessage"为该提交设置一个提交消息。

分析

这是因为LFS没有跟踪这些文件,但是它们符合一些.gitattributes文件的描述。

例如,

服务器/ .gitattributes:

conf/** filter=lfs diff=lfs merge=lfs -text

server/conf/client.conf文件太大,被LFS跟踪 服务器/ conf /客户端。gflags是在git而不是LFS中跟踪的

然而,客户端。Gflags匹配服务器/。git会从LFS中拉出它,但是它没有LFS信息,错误就会被抛出。

解决方案

找到描述与encounter文件相匹配的.gitattributes文件,删除错误的描述或优化一些通配符匹配。

优化上面的例子, 服务器/ .gitattributes:

conf/client.conf filter=lfs diff=lfs merge=lfs -text

这是我遇到的问题:

假设您创建了一个分支,并以某种方式将文件提交为非lfs。因此,您试图通过稍后在同一分支上提交文件的LFS版本来纠正它。然而,现在你不能重基或压缩,因为你会一直遇到这种“文件应该是指针,但不是”错误在重基中间。

解决使用git重置——软:https://stackoverflow.com/a/5201642/2516916

确保您已经安装了git lfs 2.5或更高版本(此处下载)。

检查你正在使用你下载的git lfs版本(我是2.7.2):

>git lfs version
git-lfs/2.7.2

Run:

Git LFS迁移导入-修复-一切

拉出分支并修复任何合并冲突。

在这个github评论中找到。

与上面的@John Kugelman一样,但我把它放在一个别名中,因为我必须这么做很多次。

    
git rm --cached -r . > /dev/null && git reset --hard > /dev/null && git rm .gitattributes > /dev/null && git reset . && git checkout . > /dev/null