如何清理回购,如果阶段性文件标记为修改?
后
git reset --hard
我得到
Encountered 7 file(s) that should have been pointers, but weren't:
运行git clean -fdx也没有帮助。
如何清理回购,如果阶段性文件标记为修改?
后
git reset --hard
我得到
Encountered 7 file(s) that should have been pointers, but weren't:
运行git clean -fdx也没有帮助。
当前回答
这是我遇到的问题:
假设您创建了一个分支,并以某种方式将文件提交为非lfs。因此,您试图通过稍后在同一分支上提交文件的LFS版本来纠正它。然而,现在你不能重基或压缩,因为你会一直遇到这种“文件应该是指针,但不是”错误在重基中间。
解决使用git重置——软:https://stackoverflow.com/a/5201642/2516916
其他回答
在我的例子中,它是一个lfs规则下的文件(我假设它是在没有安装lfs或其他东西的情况下检入的)。
所以我在.gitattributes文件中找到了它的扩展名,并将这一行注释为
#*.7z filter=lfs diff=lfs merge=lfs -text
保存这个.git属性,然后git状态显示没有问题。
之后,我取消了这一行的注释(删除了#),保存了.gitattributes和git状态仍然显示没有问题。
我有这个确切的错误与一些文件存储与git-LFS和解决它的方式一样,我已经解决了一个linending诱导borked索引。
清除缓存并进行硬复位:
git rm --cached -r .
git reset --hard
对于我来说,这比一个新鲜的克隆要快得多,因为我的repo中有巨大的git-LFS文件。
导致此错误的一个可能原因是git lfs对.gitattributes的相关更改影响了repo中已经添加的文件。
(我不确定复制的确切步骤,但问题似乎发生在我接触到一个文件时,该文件最近受到.git属性的影响,该文件以前被提交为非LFS文件,现在应该是LFS文件。切换分支似乎加剧了这个问题,或者至少在问题解决之前不可能切换分支。)
在本例中,我使用下面的步骤来防止此错误重复发生。
通过遵循这里的其他答案之一来修复您所在分支的问题(例如,清除缓存和重置。我发现BheeMa的答案很有效。) 转到你的主分支,确保git状态下没有什么要提交的 强制git重新检查并“重新应用”git属性更改
从Ratata Tata的回答如何改变。gitattributes生效)
git rm --cached -r .
git add -A
警告:确保在第2步中没有任何东西要提交,因为上面的步骤将添加以前没有版本的任何文件
Verify the results with git status (it should only have modified relevant files to become LFS pointers, i.e. files that can potentially cause the "encountered files that should have been pointers" error) and commit changes (Optionally, merge/rebase this fix to all other branches if possible. Otherwise, this error could pop up again when switching to those branches. Note that it may be necessary to repeat the initial fix for each branch as per step 1 to be safe, though it could be ok just to commit the affected files.)
与上面的@John Kugelman一样,但我把它放在一个别名中,因为我必须这么做很多次。
git rm --cached -r . > /dev/null && git reset --hard > /dev/null && git rm .gitattributes > /dev/null && git reset . && git checkout . > /dev/null
这里有一个修饰,不需要重新安装lfs钩子或模糊任何.gitattributes文件:
git -c filter.lfs.smudge= -c filter.lfs.clean= reset --hard