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

git reset --hard

我得到

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

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


当前回答

接受的答案为我工作,但它只会在我手动输入命令时工作,我把每个命令之间的睡眠,现在它作为一个bash脚本工作:

git rm --cached -r .
sleep 1
git reset --hard
sleep 1
git rm .gitattributes
sleep 1
git reset .
sleep 1
git checkout .

其他回答

下面的进程将添加一个提交,将所有应该是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"

接受的答案为我工作,但它只会在我手动输入命令时工作,我把每个命令之间的睡眠,现在它作为一个bash脚本工作:

git rm --cached -r .
sleep 1
git reset --hard
sleep 1
git rm .gitattributes
sleep 1
git reset .
sleep 1
git checkout .

这里有一个修饰,不需要重新安装lfs钩子或模糊任何.gitattributes文件:

git -c filter.lfs.smudge= -c filter.lfs.clean= reset --hard

自从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规则下的文件(我假设它是在没有安装lfs或其他东西的情况下检入的)。

所以我在.gitattributes文件中找到了它的扩展名,并将这一行注释为

#*.7z filter=lfs diff=lfs merge=lfs -text

保存这个.git属性,然后git状态显示没有问题。

之后,我取消了这一行的注释(删除了#),保存了.gitattributes和git状态仍然显示没有问题。