如何清理回购,如果阶段性文件标记为修改?
后
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指针。
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文件的描述。
例如,
服务器/ .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
我有这个确切的错误与一些文件存储与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.)
就像Travis Heeter在他的回答中提到的,试试下面的命令序列:
git lfs uninstall
git reset --hard
git lfs install
git lfs pull
如果这是不工作(因为这不是为我工作),下面的黑客可能工作:
git rm --cached -r .
git reset --hard
git rm .gitattributes
git reset .
git checkout .
这对我很管用!
当一个明显的错误突然出现时,我们的团队是这样做的:
Disable lfs for that specific type file (modifying .gitattributes or via SourceTree menus) The change will dissapear and you will see a change on .gitattributes instead Remove the problem: 3.1 One solution is to execute git reset --hard. Another way, discard changes. Sometimes the file will not come up again. 3.2.1 If the previous solution doesn't work, repeat 1 and 2. Then make sure that this branch you are in (A) has already commited and pushed everything except those annoying files. Then commit your change, but not push. 3.2.2: Go to another branch (B) 3.2.3: Remove that local branch (A) where you performed the commit to .gitattributes, forcing the removal even when it says there's a commit that hasn't been pushed. It will forget that commit (it can afterwards be removed via GC or whatever but it's not a big deal if the file that has the error is not huge) 3.2.4: Checkout the branch A again. It will download the previous status of the repository without the annoying files and LFS settings set up the correct way.
这招总是管用的!