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

git reset --hard

我得到

Encountered 7 file(s) that should have been pointers, but weren't:

运行git clean -fdx也没有帮助。


当前回答

这里有一个修饰,不需要重新安装lfs钩子或模糊任何.gitattributes文件:

git -c filter.lfs.smudge= -c filter.lfs.clean= reset --hard

其他回答

下面的进程将添加一个提交,将所有应该是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"

上面的命令对我都没用,我在这里找到了答案

git status -s | cut -c 4- | xargs git update-index --assume-unchanged
rm .git/index && git reset

帮助我的是git 2.23中添加的git恢复命令,而不涉及整个repo

git restore——source=HEAD——staging——worktree——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

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

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.

这招总是管用的!