SPM未知错误参考在更改分支时找不到
我项目的某些依赖关系托管在私人存储库上。它在大多数情况下都可以工作,但是有时候,当我用git更改当前分支时,我会遇到此错误:
❌ git@my_private_repo.git: An unknown error occurred. reference 'refs/remotes/origin/main' not found (-1)
从那时起,这是不可能编译的,我唯一的选择是重置SPM CACHE需要大量时间。
关于原因是什么以及如何解决它的任何想法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
通过运行这些命令
默认来解决问题删除com.apple.dt.xcode dvtsourcecontrolaccountdefaultskeykekey
defaults delete com.apple.pode idesourcececontrolnownonknownonkoyssshhostsshhostssshhostsdefaultsdefaultskey
sudo sudo sudo sudo sudo killall ssh-agg
ssh-gabent.com: /forums/thread/662690“ rel =“ nofollow noreferrer”> https://forums.developer.apple.com/forums/thread/662690
Solve problem by running these commands
defaults delete com.apple.dt.xcode DVTSourceControlAccountDefaultsKey
defaults delete com.apple.dt.xcode IDESourceControlKnownSSHHostsDefaultsKey
sudo killall ssh-agent
More info: https://forums.developer.apple.com/forums/thread/662690
我不必删除任何派生的数据或缓存。
我要做的就是:
I didn't have to delete any derived data or caches.
All I had to do was:
就像其他人所回答的那样,可以通过在您的项目的派生数据目录中删除Swift软件包以及
〜/library/caches/org.swift.swiftpm中的全球swift软件包管理器中的swift package caches来解决问题。
。更好的是,仅删除受影响的遥控器
目录,但是找到包装和文件夹可能会很耗时。这是我快速组合在一起的一个小脚本,它将在全局Swift软件包管理器缓存和您项目的派生数据存储库中删除所有名为
远程>的目录
。如果将代码保存在名为
fix fix-cache.sh.sh
的文件中,则可以执行chmod +x fix spm-cache.sh
使文件可执行文件。之后,只需使用项目名称运行脚本,例如./ fix-cache.sh myproject
,当您遇到Xcode中的错误时。运行脚本时,您可以保持Xcode打开。脚本完成执行后,尝试再次解决或更新软件包。它应该起作用,并且由于我们没有删除整个缓存,因此应该相对较快。
这应该解决本主题中提到的错误,以及臭名昭著的
swiftpm.spmrepositoryerror错误5
在Xcode 13中发生的错误,这可能是相同的错误,只需带有不同的消息。Like others have answered, the issue can be worked around by deleting Swift package caches both in the derived data directory of your project, as well as the global Swift Package Manager cache in
~/Library/Caches/org.swift.swiftpm
. Even better, by deleting only the affectedremotes
directory, but it can be time consuming to find the package and the folder.Here is a small script I quickly put together that will delete all directories named
remotes
both in the global Swift Package Manager cache and in the derived data repositories directory of your project.If you save the code in a file named
fix-spm-cache.sh
, then you can dochmod +x fix-spm-cache.sh
to make the file executable. Afterwards, just run the script with the project name, like./fix-spm-cache.sh myproject
, when you encounter the error in Xcode.You can keep Xcode open while running the script. Once the script finishes executing, try resolving or updating your packages again. It should work, and it should be relatively fast since we are not deleting the whole cache.
This should resolve both the error mentioned in this topic, as well as the infamous
SwiftPM.SPMRepositoryError error 5
that happens in Xcode 13, which is probably the same error, just with a different message.我想我可能在这里找到了这个问题!经过大量的挖掘后,Xcode和Swift PM似乎使用GIT@而不是https://
使用SSH的错误,我们在我们的caches和派生的数据中获得了悬挂式ref c。使用HTTPS时,情况并非如此。这是有道理的,因为我们项目中使用SSH的唯一的DEP是我们的内部二;
我通过添加全新的第三方依赖性 jpsim/yams.git进入我们的项目,并在org.swift.swiftpm中看到了缓存。
更新:10天后,这似乎一直都是问题。但是,即使更改了参考文献,它也进行了完整的deveriveddata/spm缓存/软件包。在Xcode不再对
git@
repos的引用之前解决。我已经向Apple提交了此错误的反馈。I think I may have found the issue here! After a ton of digging it seems Xcode and Swift PM has a bug with repos using git@ rather than https://
Using ssh we are getting a hanging ref to remote/origin/main in our caches and derived data. When using https this is not the case. This makes sense as the only dep in our project using ssh are our internal deps.
I tested this by adding a brand new 3rd party dependency [email protected]:jpsim/Yams.git into our project and saw the cache in org.swift.swiftpm update incorrectly.
UPDATE: 10 days later and it seems this was the issue all along. However even after changing the references it took a full DerivedData/SPM cache/Package.resolved wipe before Xcode no longer had any references to the
git@
repos. I've filed a feedback with Apple for this bug.在没有“重置软件包缓存”按钮的Xcode和AppCode中遇到此问题后,当您删除derivedData文件夹时,我将永远重新索引整个iOS框架,我尝试最大程度地减少删除所需的文件夹。
我最终得到了以下内容:
一旦获得错误消息
,您
〜/library/developer/xcode/xcode/deriveddata/code>)(对于AppCode,for AppCode,它位于
〜/library/caches/jetbrains/appcode2022.2/deriveddata
中)< yourProject> - > - &lt randych; randomch; randych; gt; gt; gt; gt; /sourcepackages/repositories/< failinglibraryProject> - < randancharacters>/refs/
远程>遥控器
folder这就是全部需要的 - 至少对我而言。我想您需要重复每个为您失败的图书馆项目的步骤。
最好的事情是:无论我切换分支机构或依赖性版本多少次,我都不需要再做一次:)
After having this problem in XCode and AppCode, which does not have a "Reset Package Cache" button and takes forever re-indexing the whole iOS Framework when you delete the DerivedData folder, i tried to minimize the folders i needed to delete.
I ended up with the following:
Once you get the error message
[email protected]: An unknown error occurred. reference 'refs/remotes/origin/main' not found (-1)
, you~/Library/Developer/Xcode/DerivedData/
) (for AppCode, it's located in~/Library/Caches/JetBrains/AppCode2022.2/DerivedData
)<YourProject>-<RandomCharacters>/SourcePackages/repositories/<FailingLibraryProject>-<RandomCharacters>/refs/
remotes
folderThat's all it takes - at least for me. I guess you need to repeat the steps for every library project that's failing for you.
And the best thing: I never need to do this again, no matter how many times i switch branches or dependency versions :)
也有同样的问题,甚至创建了具有相同内容的新存储库,以确保其正常工作。最后,我找到了一种帮助我的解决方案。
SWIFT软件包净化库 - CACHE
rm -rf〜/library/developer/xcode/deriveddata
ps
吹扫 - cache
w/o删除deriveddata
无法使用,但可能只需要删除deriveddata
才能解决此问题。无法重新检查,因为我再也无法再现此问题了。upd:不需要步骤#3。
Had same issue, even created new repo with same content to see that it is working. In the end I found a solution that helped me.
swift package purge-cache
rm -rf ~/Library/Developer/Xcode/DerivedData
P.S.
purge-cache
w/o removingDerivedData
not worked, but it could be that only removingDerivedData
was required to solve this issue. Can not re-check as I can not reproduce this issue anymore.UPD: Step #3 not required.
今天似乎对我有用的东西,只需几秒钟,并且不会删除派生的数据文件夹:
似乎再次正常。
Something that seemed to work for me today, that only takes a few seconds and that doesn't delete the derived data folder :
After a few seconds, everything seemed to be normal again.
我遇到了相同的错误,但是通过HTTPS添加了回购。我刚刚删除了
〜/library/caches/org.swift.swiftpm
的缓存,并且似乎有效。重置软件包,清晰的派生数据无济于事。I had the same error but with repo added via https. I just removed cache at
~/Library/Caches/org.swift.swiftpm
and seems like it works. Reset packages, clear derived data didn't help.在上面可以找到多个功能的解决方法。
我使用了这种方法:
〜/library/caches/org.swift.swiftpm
〜/library/developer/xcode/xcode/deriveddata/yourprojectName
不幸,RE,RE - 下载软件包可能需要很长时间 - 当只有单个存储库失败时,请再次对它们进行编译。
我不确定为什么原因Xcode的初始获取成功及其后续获取失败 - Xcode也不会:“未知错误”。弄清楚原因是什么。我的机器上的某些设置似乎是错误的,因为我的同事没有这个问题。不幸的是,我无法弄清楚。
因此,我最终构建了这个解决方法,这只是做什么,Xcode不做的事情:取回库,通常会失败。它通过进入
deriveddata
文件夹并获取全部或指定的存储库来做到这一点。然后,Xcode将能够解析包装。我将此功能放入我的
.profile
(对不起,我仍在使用bash)。您可以在没有参数的情况下调用此函数,也可以使用未下载的软件包的名称来调用此功能:
或者
我建议列出失败的软件包,因为它更快。
希望,它对您有帮助。
Multiple functioning workarounds can be found above.
I used this approach:
~/Library/Caches/org.swift.swiftpm
~/Library/Developer/Xcode/DerivedData/YourProjectName
Unfortunately, re-downloading the packages could take a very long time - as well as compiling them all again, when only a single repo fails.
I am not sure why reason Xcode's initial fetch succeeds and its subsequent fetches fail - neither does Xcode: "unknown error". It would be good to figure out, what the cause is. Some setup on my machine seems to be wrong, as my colleagues don't have this problem. Unfortunately, I could not figure it out.
So I ended up building this workaround, that just does what, that Xcode does not do: fetching the repos, that usually fail. It does so by going into the
DerivedData
folder and fetching either all or the specified repos. Xcode will then be able to resolve the packages.I put this function into my
.profile
(sorry, I am still using bash).You can call this function without parameters or with the names of the packages failing to download:
or
I recommend listing the failing package(s) because it is quicker.
Hope, it helps you.
我制作了一个Python脚本来解决这个问题。
这个想法是获取最新的提交哈希并将其写入包装。分辨,然后为您解决packaggations。
您可以在下面获取脚本,也可以从“ noreflowl noreferrer”>中
I made a python script to fix the issue.
The idea is to get the latest commit hash and write it to Package.resolved, then resolvePackageDependencies for you.
You can get the script below, or download from here
Put the script in your xcode project, along with your
*.xcodeproj
or*.xcworkspace
.Then run
or
If you don't have python: