如何清理回购,如果阶段性文件标记为修改?
后
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跟踪(如.gitattributes中指定的那样),但它们却被直接提交了。大多数情况下,您有另一个程序管理您的存储库,如git GUI或IDE。
这可能会令人沮丧,因为这些文件不知从哪里冒出来,阻止您进行签出。只要您将更改隐藏起来,它们就会返回!如果您陷入这种情况,一个快速的解决方法是在一个临时分支上提交这些更改,这样您就可以再次签出。
要真正解决这个问题,请确保将文件提交为LFS指针。这应该和使用git add一样简单。在提交之前使用git lfs状态检查你的工作。git lfs ls-files将显示lfs正在管理的文件。
git lfs状态是误导性的,因为当它真正列出所有更改时,它会读取git lfs对象以提交。您希望由LFS跟踪的文件应该读取类似于(LFS: c9e4f4a)或(Git: c9e4f4a -> LFS: c9e4f4a)的文件,而不是(Git: c9e4f4a)。
举例来说,我发现这是一个问题,当通过Xcode 9.2添加图像资产时,我添加了“CalendarChecked.png”,它会自动添加:
$ git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png
$ git lfs status
Git LFS objects to be committed:
Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (Git: c9e4f4a)
Git LFS objects not staged for commit:
Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (File: c9e4f4a)
$ git add Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png`
$ git lfs status
Git LFS objects to be committed:
Empty/Empty/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (LFS: c9e4f4a)
Git LFS objects not staged for commit:
$
其他回答
下面的进程将添加一个提交,将所有应该是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"
这可能发生在您执行包含文件的签出时,这些文件本应由LFS跟踪(如.gitattributes中指定的那样),但它们却被直接提交了。大多数情况下,您有另一个程序管理您的存储库,如git GUI或IDE。
这可能会令人沮丧,因为这些文件不知从哪里冒出来,阻止您进行签出。只要您将更改隐藏起来,它们就会返回!如果您陷入这种情况,一个快速的解决方法是在一个临时分支上提交这些更改,这样您就可以再次签出。
要真正解决这个问题,请确保将文件提交为LFS指针。这应该和使用git add一样简单。在提交之前使用git lfs状态检查你的工作。git lfs ls-files将显示lfs正在管理的文件。
git lfs状态是误导性的,因为当它真正列出所有更改时,它会读取git lfs对象以提交。您希望由LFS跟踪的文件应该读取类似于(LFS: c9e4f4a)或(Git: c9e4f4a -> LFS: c9e4f4a)的文件,而不是(Git: c9e4f4a)。
举例来说,我发现这是一个问题,当通过Xcode 9.2添加图像资产时,我添加了“CalendarChecked.png”,它会自动添加:
$ git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png
$ git lfs status
Git LFS objects to be committed:
Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (Git: c9e4f4a)
Git LFS objects not staged for commit:
Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (File: c9e4f4a)
$ git add Example/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png`
$ git lfs status
Git LFS objects to be committed:
Empty/Empty/Assets.xcassets/CalendarChecked.imageset/CalendarChecked.png (LFS: c9e4f4a)
Git LFS objects not staged for commit:
$
我有这个确切的错误与一些文件存储与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.)
确保您已经安装了git lfs 2.5或更高版本(此处下载)。
检查你正在使用你下载的git lfs版本(我是2.7.2):
>git lfs version
git-lfs/2.7.2
Run:
Git LFS迁移导入-修复-一切
拉出分支并修复任何合并冲突。
在这个github评论中找到。