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

git reset --hard

我得到

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

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


当前回答

在我的例子中,它是一个lfs规则下的文件(我假设它是在没有安装lfs或其他东西的情况下检入的)。

所以我在.gitattributes文件中找到了它的扩展名,并将这一行注释为

#*.7z filter=lfs diff=lfs merge=lfs -text

保存这个.git属性,然后git状态显示没有问题。

之后,我取消了这一行的注释(删除了#),保存了.gitattributes和git状态仍然显示没有问题。

其他回答

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

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

>git lfs version
git-lfs/2.7.2

Run:

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

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

在这个github评论中找到。

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

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

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

git restore——source=HEAD——staging——worktree——affected_files

执行该命令几次,直到所有警告消失。

这可能发生在您执行包含文件的签出时,这些文件本应由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:

$

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

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.

这招总是管用的!