git repo 初始化一个特定的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10818758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
repo init a particular commit
提问by renzoe
Im building the Cyanogenmod 9 (Android ICS) system for a Nexus S phone (samsung crespo). The problem is that if I do:
我正在为 Nexus S 手机(三星 Crespo)构建 Cyanogenmod 9(Android ICS)系统。问题是,如果我这样做:
repo init -u git://github.com/CyanogenMod/android.git -b ics
The repo inits to the latest commit of ICS, in which the manifest does not include some device/samsung/ projects I need (specifically https://github.com/CyanogenMod/android_device_samsung_crespo).
该 repo 初始化为 ICS 的最新提交,其中清单不包括我需要的一些设备/三星/项目(特别是https://github.com/CyanogenMod/android_device_samsung_crespo)。
How do I repo init to a particular commit? In my case I want the last commit using the google android-4.0.3_r1 branch. Is this one:
如何将 init 重新存储到特定提交?就我而言,我希望使用 google android-4.0.3_r1 分支进行最后一次提交。这是一个:
If I do
如果我做
repo init -u git://github.com/CyanogenMod/android.git -b commit-hash
repo init -u git://github.com/CyanogenMod/android.git -b commit-hash
Does not work, seems that repo init -b only support the HEAD of a branch.
不起作用,似乎 repo init -b 只支持分支的 HEAD。
Thanks in Advance.
提前致谢。
采纳答案by Andrejs Cainikovs
Long answer:
长答案:
You can't specify a branch name (or SHA, or whatever else) to repo
, it will not work. Here's why:
您不能为 指定分支名称(或 SHA,或其他任何名称)repo
,它将不起作用。原因如下:
repo
is a script that handles a collection of repository projects (which in fact are independent git's). Project list is located in .repo
git, and contains a manifest file, which basically is a list of all repository git's and they branches. -b
is relevant only for repo
git during repo init
.
repo
是一个处理存储库项目集合(实际上是独立的 git 项目)的脚本。项目列表位于.repo
git 中,并包含一个清单文件,该文件基本上是所有存储库 git 及其分支的列表。-b
仅与repo
git 期间相关repo init
。
Here is an example of .repo/manifests/default.xml
:
下面是一个例子.repo/manifests/default.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote fetch="git://address.com/" name="origin"
review="review.address.com"/>
<default remote="origin" revision="ics-something" sync-j="4"/>
<manifest-server url="http://manifests.address.com:8000"/>
<!-- sniff -->
<project name="platform/external/libxml2" path="external/libxml2"
revision="ics-common"/>
<project name="platform/external/zlib" path="external/zlib"
revision="ics-common"/>
<project name="platform/frameworks/base" path="frameworks/base"
revision="ics-something"/>
<project name="platform/packages/apps/Bluetooth" path="packages/apps/Bluetooth"
revision="ics-common"/>
<!-- sniff -->
</manifest>
So, the correct way of obtaining the sources of the repository for the particular build is to obtain it's manifest.
I.e., manifest, that will contain SHA's (or tags, which are practically the same, if they are present) instead of branch names. This way every git project within your repository will point into some commit, that was the latest greatest when the build was executed:
因此,获取特定构建的存储库源的正确方法是获取它的清单。
即清单,将包含 SHA(或标签,如果它们存在的话,实际上是相同的)而不是分支名称。这样,您存储库中的每个 git 项目都将指向某个提交,这是执行构建时最新的最大提交:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote fetch="git://address.com/" name="origin"
review="review.address.com"/>
<default remote="origin" revision="ics-something" sync-j="4"/>
<manifest-server url="http://manifests.address.com:8000"/>
<!-- sniff -->
<project name="platform/external/libxml2" path="external/libxml2"
revision="refs/tags/android-4.0.4_r1.1"/>
<project name="platform/external/zlib" path="external/zlib"
revision="refs/tags/android-4.0.4_r1.1"/>
<project name="platform/frameworks/base" path="frameworks/base"
revision="ecb41a77411358d385e3fde5b4e98a5f3d9cfdd5"/>
<project name="platform/packages/apps/Bluetooth" path="packages/apps/Bluetooth"
revision="621bae79f1a250e443eb83d1f473c533bea493dc"/>
<!-- sniff -->
</manifest>
As you see, the only difference between these two manifests is the revision values of repository git's.
如您所见,这两个清单之间的唯一区别是存储库 git 的修订值。
Short answer:
简答:
You need to obtain manifest_static.xml
of the particular build.
您需要获得manifest_static.xml
特定版本。
Or, if you just missing some project git's, then you could create local_manifest.xml
file in .repo
git, add missing git's there, and then repo sync
from the root of your repository. More info on local_manifest.xml
usage is here.
或者,如果您只是缺少一些项目 git,那么您可以local_manifest.xml
在.repo
git 中创建文件,在那里添加缺少的 git,然后repo sync
从存储库的根目录中添加。有关local_manifest.xml
使用的更多信息在这里。
回答by Renaud Mathieu
I figured it out. If your have a tag in a manifest file (version.xml for example). You can repo init to a specific tag with the following command:
我想到了。如果您在清单文件(例如 version.xml)中有一个标签。您可以使用以下命令将 init 重新存储到特定标签:
repo init -u <addres> -b refs/tags/<tagname> -m version.xml
回答by Rob
I don't have sufficient authority to submit a comment, but I just wanted to clarify Andrejs Cainikovs's answer.
我没有足够的权限提交评论,但我只是想澄清 Andrejs Cainikovs 的回答。
Repo does accept a commit-id SHAin addition to a branch ref as an argument to the -b option.
除了作为 -b 选项的参数的分支 ref 之外,Repo还接受 commit-id SHA。
As the answers suggest, this argument specifies the revision of the manifest that should be used by repo, not a revision in any of the projects that the manifest refers to.
正如答案所暗示的那样,此参数指定了 repo 应使用的清单修订版,而不是清单所引用的任何项目中的修订版。