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

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 .

其他回答

当一个明显的错误突然出现时,我们的团队是这样做的:

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.

这招总是管用的!

run

git add --renormalize .

并提交这些更改。即使当另一个用户在另一个分支上做同样的事情时,这样做也是安全的,因为LFS指针是从文件的散列派生的。它还可能捕获一些行尾错误的文件。

确保您已经安装了git lfs 2.5或更高版本(此处下载)。

检查你正在使用你下载的git lfs版本(我是2.7.2):

>git lfs version
git-lfs/2.7.2

Run:

Git LFS迁移导入-修复-一切

拉出分支并修复任何合并冲突。

在这个github评论中找到。

这是我遇到的问题:

假设您创建了一个分支,并以某种方式将文件提交为非lfs。因此,您试图通过稍后在同一分支上提交文件的LFS版本来纠正它。然而,现在你不能重基或压缩,因为你会一直遇到这种“文件应该是指针,但不是”错误在重基中间。

解决使用git重置——软:https://stackoverflow.com/a/5201642/2516916

就像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 .

这对我很管用!