当 Package Manager 从 Git 代码仓库获取包时,会将包添加到项目本地。这使您可以轻松测试未发布的更改,但不能将对包的更改合并到该 Git 代码仓库。要将现有的本地 Git 代码仓库设置为项目中的依赖项,请改用本地路径。
要在项目中使用 Git 包,请确保您的计算机上安装了 Git 客户端,并且已将 Git 可执行路径添加到 PATH 系统环境变量中。
如果代码仓库使用 Git LFS 来跟踪文件,请确保您的计算机上还安装了 Git LFS 客户端。如果未安装,则 Package Manager 无法获取存储在 LFS 服务器上的文件,而是签出 LFS 指针文件,并且不会显示任何错误或警告消息。
注意:还可以使用 Package Manager 窗口直接从 Git 代码仓库安装包。有关更多信息,请参阅从 Git URL 安装。
要将 Git URL 指定为依赖项,请添加要使用 Git URL 安装的包名称,而不是版本号或本地文件路径。例如,下面演示了如何使用推荐的 HTTPS 协议指定远程 Git:
{
"dependencies": {
"com.mycompany.mypackage": "https://mycompany.github.com/gitproject/com.mycompany.mypackage.git"
}
Package Manager 支持 https、http、ssh、git 和 file 协议,使用的格式如下:
<protocol>://[<user>[:<password>]@]<host>[:<port>]/<path>.git[#<revision>]
如果 URL 以如下格式的 git 开头,也可以跳过 .git
路径后缀:
git://[<user>[:<password>]@]<host>[:<port>]/<path>[#<revision>]
或:
git+<protocol>://[<user>[:<password>]@]<host>[:<port>]/<path>[#<revision>]
可能需要在 Git 配置文件中配置凭据,以便安全地提供用户名和密码。这比在 Git URL 中对凭据进行硬编码更安全,如果与他人共享项目,硬编码会是一个主要的安全问题。
当您使用 SSH 进行身份验证时,Git 会使用默认位置的密钥。但是,如果您在 Windows 上使用 PuTTY 作为 SSH 客户端,则可能需要配置 GIT_SSH 环境变量以使其指向 plink.exe
。
您需要在 Unity 外部设置 SSH 密钥。如果您没有适当的访问权限,Editor 会通知您身份验证失败。
有关为特定主机设置身份验证的更多信息,请参阅 GitLab 和 GitHub 的帮助页面。
您可以指定要安装的任何修订版本。修订版本是一个最终在 Git 中解析为提交哈希的表达形式。修订版本的最常见类型是提交哈希、标签和分支。
要定位某个特定修订版本,请将 # 及随后的修订版本(版本或特定 Git 哈希)附加到 dependencies 属性中的 Git URL。指定哈希可确保您准确获得所需的版本。例如:
{
"dependencies": {
"com.mycompany.mypackage": "https://mycompany.github.com/gitproject/com.mycompany.mypackage.git#523c4f291cea796141e7211f4951702984d2e9ca"
}
}
如果省略了修订版本,则 Package Manager 将使用远程代码仓库的 HEAD
修订版本。
有关设置正确修订版本的更多信息,请参阅 Git 用户手册中有关 Git 修订版本的章节。
如果要使用 ssh 协议,则可以使用完整的 URL 语法或 SCP 缩写:
# SCP shorthand
{
"dependencies": {
"com.mycompany.mypackage": "git@mycompany.github.com:gitproject/com.mycompany.mypackage.git"
}
# Full SSH protocol
{
"dependencies": {
"com.mycompany.mypackage": "ssh://git@mycompany.github.com/gitproject/com.mycompany.mypackage.git"
}
注意:如果您使用口令短语设置 SSH 密钥,则 Package Manager 将无法获取包,因为您需要在 shell 或命令行中输入口令短语。在这种情况下,请考虑改用 https 协议,或使用 Git 附带的 ssh-add 实用程序。有关更多信息,请参阅 Git URL 的身份验证问题。
Package Manager 无法将带有 file 前缀的文件路径识别为 Git URL,但是如果格式正确,可以将带有 file 协议的完整 URL 识别为 Git URL。例如:
{
"dependencies": {
"com.mycompany.mypackage1": "file://localhost/absolute/path/to/com.mycompany.mypackage1.git",
"com.mycompany.mypackage2": "git+file:///absolute/path/to/other/com.mycompany.mypackage2"
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.