repo init a particular commit

I don't have sufficient authority to submit a comment, but I just wanted to clarify Andrejs Cainikovs's answer.

Repo does accept a commit-id SHA in addition to a branch ref as an argument to the -b option.

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.


Long answer:

You can't specify a branch name (or SHA, or whatever else) to repo, it will not work. Here's why:

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.

Here is an example of .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 is specified in the manifest file:

<?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.

Short answer:

You need to obtain manifest_static.xml of the particular build.

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.


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:

repo init -u <addres> -b refs/tags/<tagname> -m version.xml