git 如何在本地 repo 中切换 android 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14008113/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:55:12  来源:igfitidea点击:

How to switch android version in local repo?

androidgittagsrepositorygit-checkout

提问by Jiaqi Liu

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:

同步成功后,我想将工作树切换到 android 2.3.7。你看我在“repo init”时没有用“-b”参数指定分支。所以我想应该下载所有标签信息,我可以使用以下命令轻松切换到 android 2.3.7:

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?

那么如何在没有“repo init -b android-2.3.7_r1”和“repo sync”的情况下再次切换到android 2.3.7?

回答by mvp

You cannot solve this problem using repo forall.

您无法使用repo forall.

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

让我们确定您当前的 Android 树是干净的 - 没有本地更改或提交,即repo status什么都不显示。

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:

要正确切换 Android 版本,您只需更改清单存储库的分支即可。首先确定具有不同 Android 版本清单的可用分支:

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 initwith -b(without -u) will only update manifest branch and will not otherwise touch your tree.

这种有选择性的repo initwith -b(without -u) 只会更新清单分支,而不会以其他方式触及您的树。

Now, simply sync it:

现在,只需同步它:

repo sync -j8

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

一段时间后,您的 Android 树将切换到另一个版本。

Speed of this operation is mostly determined by how much default.xmlmanifest 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.

此操作的速度主要取决于default.xml新旧 Android 版本之间的清单文件有多少差异 - 因为如果在新清单中添加了一些 git 存储库,它将花费时间克隆它。如果某个存储库被删除, if 会真正将其吹走。

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

但是,总的来说,这种方法仍然比从头开始初始化全新的 Android 树要快得多。

回答by john liao

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.

如果您所在的分支和您将切换到的分支具有相同的 manifest.xml 文件,那么您可以使用以下命令来执行此操作。

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

另请参阅http://johnliao52.github.io/2016/03/27/git-repo-skills.html 中的详细信息