如何清理回购,如果阶段性文件标记为修改?
后
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也没有帮助。
当前回答
问题来自于git LFS在.git属性中标记为要跟踪的文件类型与一些已经在传统的非LFS版本控制下的匹配文件之间的不匹配。
所以这里最简单的解决方法是暂时删除.gitattributes文件:
git rm .gitattributes
git reset .
git checkout .
之后,您可以结帐任何其他分支。
另外一个建议:当添加一个新的文件类型到git LFS时,最好不要手动修改.gitattributes,而是通过运行:
git lfs track PATTERN
其中PATTERN是匹配文件的模式,例如*.so
通过这种方式,所有匹配新的跟踪模式的非LFS版本文件将被标记为dirty,并可以简单地添加,即转换为git LFS(文件指针)。
其他回答
这是我遇到的问题:
假设您创建了一个分支,并以某种方式将文件提交为非lfs。因此,您试图通过稍后在同一分支上提交文件的LFS版本来纠正它。然而,现在你不能重基或压缩,因为你会一直遇到这种“文件应该是指针,但不是”错误在重基中间。
解决使用git重置——软:https://stackoverflow.com/a/5201642/2516916
run
git add --renormalize .
并提交这些更改。即使当另一个用户在另一个分支上做同样的事情时,这样做也是安全的,因为LFS指针是从文件的散列派生的。它还可能捕获一些行尾错误的文件。
这只是再次显示什么一堆狗**** GIT-LFS。
你可能会遇到这种情况,如果:
文件包含在common-base-branch中,而不是LFS中 在基于common-base-branch的分支LFS -branch中,文件被移动到LFS 在另一个同样基于common-base-branch的非lfs-branch分支中,修改了文件。
或者:
文件不包含在common-base-branch中 在基于common-base-branch的分支LFS -branch中,文件被添加到LFS 在另一个同样基于common-base-branch的非LFS -branch分支中,文件被添加(但不是添加到LFS。
在这两种情况下,当您尝试将非lfs-branch合并到lfs-branch时,都会得到这种错误。
您可能会问,为什么会出现这种情况,但答案是,许多软件是由不止一个人开发的(这就是为什么会有像GIT这样的版本控制系统),而且人们并不总是彼此交谈,或者LFS是后来在一个特性分支的项目历史中引入的,而“正常”的开发仍然在其他分支中进行。
这是一种合法的合并冲突情况,而不是错误或损坏的工作目录或任何东西(正如其他一些答案所暗示的那样)。GIT-LFS只是处理得不好。
您现在要做的是确保冲突文件的正确版本进入GIT-LFS,因此您可能想要选择这个问题的答案…(注意事项:插入至少一个有效答案的链接)
当一个明显的错误突然出现时,我们的团队是这样做的:
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.
这招总是管用的!
上面的命令对我都没用,我在这里找到了答案
git status -s | cut -c 4- | xargs git update-index --assume-unchanged
rm .git/index && git reset