How to switch android version in local repo?

2019-03-09 21:16发布

问题:

I have downloaded whole working tree with the following command:

repo init -u https://android.googlesource.com/platform/manifest
repo sync -j8

After syncing successfully, I want to switch working tree to android 2.3.7. You see I didn't specify branch with "-b" parameter when "repo init". So I guess all tag info should be downloaded and I can easily switch to android 2.3.7 with the following command:

repo forall -c git checkout android-2.3.7_r1

But it produces many errors like:

error: pathspec 'android-2.3.7_r1' did not match any file(s) known to git.

So how can I switch to android 2.3.7 without "repo init -b android-2.3.7_r1" and "repo sync" again?

回答1:

You cannot solve this problem using repo forall.

Lets assume for certainty that your current Android tree is clean - no local changes or commits, i.e. repo status shows nothing.

To properly switch Android version, all you need to change is branch for your manifest repository. First determine the available branches with manifests for the different Android versions:

cd $ANDROID_ROOT
cd .repo/manifests
git branch -av   # see all available branches on origin

Select a version and

cd $ANDROID_ROOT
repo init -b <my_selected_android_version>

Such selective repo init with -b (without -u) will only update manifest branch and will not otherwise touch your tree.

Now, simply sync it:

repo sync -j8

and some time later, your Android tree will switch to another version.

Speed of this operation is mostly determined by how much default.xml manifest file differs between old and new Android versions - because if some git repository was added in new manifest, it will spend time cloning it. And if some repository was removed, if will actually blow it away.

But, by and large, this method is still much faster than initializing brand new Android tree from scratch.



回答2:

if the branch you are in and the branch you will switch to has the same manifest.xml file, then you can use the following commands to do that.

repo forall -c git fetch aosp --tags repo forall -c git checkout -b john5.1.1_r14_api22 android-5.1.1_r14

also see details in http://johnliao52.github.io/2016/03/27/git-repo-skills.html