如何清理回购,如果阶段性文件标记为修改?
后
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跟踪(如.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:
$
我有这个确切的错误与一些文件存储与git-LFS和解决它的方式一样,我已经解决了一个linending诱导borked索引。
清除缓存并进行硬复位:
git rm --cached -r .
git reset --hard
对于我来说,这比一个新鲜的克隆要快得多,因为我的repo中有巨大的git-LFS文件。
这些解决方案都不适合我,但我拼凑了一些资源,最终解决了所有这些问题。
Push any changes you don't want to lose If you can... If not, or if you don't care about your changes, press on. Stop Everything SourceTree, any servers, file explorers and browsers. Sometimes this stuff won't work if it's being used somewhere else. When in doubt, stop it - with this it's better to overkill. Also, go into Task Manager, force quit any bash.exe processes. Git Bash tends to hold files open after you close the window. Open a Command Window (or Terminal) cd to your local repo. Uninstall lfs > git lfs uninstall Then it'll say something like: Hooks for this repository have been removed. Global Git LFS configuration has been removed. Reset > git reset --hard It'll go through a lot of output probably... Reinstall lfs > git lfs install This may again say it found files that should have been pointers but weren't. That's OK, keep going! Pull with lfs > git lfs pull Hopefully pulling with lfs will overwrite the files that got borked. A few of my sources said at this point their repo was working again, but not me personally. You can open SourceTree or whatever to check if you want, but you may have to start from the top if it didn't work. Migrate The core issue here is that lfs, instead of downloading large files like audio, video, images - anything larger than 1Mb - it just points to them on a server. This is useful if you have a bunch of large files, you're not pulling down all that stuff. So your local repo is smaller and nimbler. However, through circumstances I'm not sure about, it seems possible to corrupt the pointers. I'm sure this is an issue that the lfs people are aware of and are working on, but for now we have to work it out ourselves. What we've done so far is uninstall lfs delete everything reinstall lfs pull everything So now we have all these things in our folder that are either files or pointers to files, and lfs needs to figure out if any files should be pointers and vise versa. And hopefully by performing the steps above we deleted the corrupted pointers. So we're going to perform migrate to kick off the procedure that goes through the files on the repo, and if they're greater than 1Mb, lfs is going to replace them with a pointer. > git lfs migrate More Errors Here's a point at which others have stopped and said they were working again, but not me. I got an error: Error in git rev-list... exit status 128 fatal: bad revision '...v1.0.0' @guneyozsan over at a github help page, posted this final piece to the puzzle, even though it didn't fix his issue. > git lfs migrate info --include-ref=v1.0.0 Notice the version matches the version that errored - v1.0.0. You will need to replace v1.0.0 with whatever version you got in your error. I haven't found a source on why this error occurs but my guess is that the lfs version number generated by migrate on your local repo doesn't match the source version. For me, all this started when SourceTree crashed during a push and I forced a machine reboot, and when that happens, lfs doesn't know how to deal with it, so it just gets stuck in this loop where it's trying to update, but it can't read the corrupted data. Hence the lengthy troubleshooting. Stash and Pull
当您打开SourceTree时,您可能会看到它想要将您的所有文件添加回来。不要那样做。藏起来,然后拉出来。
然后,恐怖事件有望结束。如果没有,这个git集线器页面或这个可能会帮助你更多,但这对我来说是有效的。
就像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 .
这对我很管用!
确保您已经安装了git lfs 2.5或更高版本(此处下载)。
检查你正在使用你下载的git lfs版本(我是2.7.2):
>git lfs version
git-lfs/2.7.2
Run:
Git LFS迁移导入-修复-一切
拉出分支并修复任何合并冲突。
在这个github评论中找到。
当一个明显的错误突然出现时,我们的团队是这样做的:
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.
这招总是管用的!
下面的进程将添加一个提交,将所有应该是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 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.)
自从git lfs 2.5.0以来,有一个新的命令可以让这变得更容易(docs):
git lfs migrate import --no-rewrite "broken file.jpg" "another broken file.png" ...
这将文件“迁移”到git lfs中,根据.gitattributes应该在lfs中,但目前没有(这就是出现错误消息的原因)。
——no-rewrite阻止git将此应用于旧的提交,而是创建一个新的提交。
使用-m "commitmessage"为该提交设置一个提交消息。
如果你只是想摆脱那个糟糕的承诺,你可以回到master by
git reset --soft origin/master
git reset --hard
然后你从讨厌的7非lfs文件中解脱出来:-)
问题来自于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
接受的答案为我工作,但它只会在我手动输入命令时工作,我把每个命令之间的睡眠,现在它作为一个bash脚本工作:
git rm --cached -r .
sleep 1
git reset --hard
sleep 1
git rm .gitattributes
sleep 1
git reset .
sleep 1
git checkout .
上面的命令对我都没用,我在这里找到了答案
git status -s | cut -c 4- | xargs git update-index --assume-unchanged
rm .git/index && git reset
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,因此您可能想要选择这个问题的答案…(注意事项:插入至少一个有效答案的链接)
在我的例子中,它是一个lfs规则下的文件(我假设它是在没有安装lfs或其他东西的情况下检入的)。
所以我在.gitattributes文件中找到了它的扩展名,并将这一行注释为
#*.7z filter=lfs diff=lfs merge=lfs -text
保存这个.git属性,然后git状态显示没有问题。
之后,我取消了这一行的注释(删除了#),保存了.gitattributes和git状态仍然显示没有问题。
与上面的@John Kugelman一样,但我把它放在一个别名中,因为我必须这么做很多次。
git rm --cached -r . > /dev/null && git reset --hard > /dev/null && git rm .gitattributes > /dev/null && git reset . && git checkout . > /dev/null
分析
这是因为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
在这个问题上有多个步骤来解决。
如果你只是处于一个破碎的状态,就像卡在一个分支上,因为你不能重置/丢弃对问题文件的更改:删除.gitattributes文件可能足以让你进行下一次git移动。一旦你移动了你的git,你可能需要恢复.gitattributes文件,但至少你摆脱了困境。
我希望我在尝试上述所有方法之前就知道这一点。至少尝试一下是一个低风险的选择。
这里有一个修饰,不需要重新安装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
执行该命令几次,直到所有警告消失。