Git和Repo扫盲——如何取得Android源代码

本文介绍Git及Repo的基本概念与操作流程,包括安装Git、配置Repo、初始化与同步版本库等关键步骤,帮助读者快速掌握获取Android源代码的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的分布式版本控制软件,它不同于Subversion、CVS这样的集中式版本控制系统。在集中式版本控制系统中只有一个仓库(repository),许多个工作目录(working copy),而像Git这样的分布式版本控制系统中(其他主要的分布式版本控制系统还有BitKeeper、Mercurial、GNU Arch、Bazaar、Darcs、SVK、Monotone等),每一个工作目录都包含一个完整仓库,它们可以支持离线工作,本地提交可以稍后提交到服务器上。分布式系统理论上也比集中式的单服务器系统更健壮,单服务器系统一旦服务器出现问题整个系统就不能运行了,分布式系统通常不会因为一两个节点而受到影响。

因为Android是由kernel、Dalvik、Bionic、prebuilt、build等多个Git项目组成,所以Android项目编写了一个名为Repo的Python的脚本来统一管理这些项目的仓库,使得Git的使用更加简单。

这几天William为了拿Android最新的sourcecode,学习了一下git和repo的一些基本操作,整理了一个如何取得Android代码的How-To,今天把他贴上来。


1、Git的安装
在Ubuntu 8.04上安装git只要设定了正确的更新源,然后使用apt-get就可以了,有什么依赖问题,就让它自己解决吧。其中cURL是一个利用URL语法在命令行下工作的文件传输工具,会在后面安装Repo的时候用到。
sudo apt-get install git-core curl

2、安装Repo
首先确保在当前用户的主目录下创建一个/bin目录(如果没有的话),然后把它(~/bin)加到PATH环境变量中
接下来通过cURL来下载Repo脚本,保存到~/bin/repo文件中
curl http://android.git.kernel.org/repo >~/bin/repo

别忘了给repo可执行权限
chmod a+x ~/bin/repo

3、初始化版本库
如果是想把Android当前主线上最新版本的所有的sourcecode拿下来,我们需要repo的帮助。
先建立一个目录,比如~/android,进去以后用repo init命令即可。
repo init -u git://android.git.kernel.org/platform/manifest.git
这个过程会持续很长的时间(至少可以好好睡一觉),具体要多少时间就取决于网络条件了
最后会看到 repo initialized in /android这样的提示,就说明本地的版本库已经初始化完毕,并且包含了当前最新的sourcecode。

如果想拿某个branch而不是主线上的代码,我们需要用-b参数制定branch名字,比如:
repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake

另一种情况是,我们只需要某一个project的代码,比如kernel/common,就不需要repo了,直接用Git即可。
git clone git://android.git.kernel.org/kernel/common.git
这也需要不少的时间,因为它会把整个Linux Kernel的代码复制下来。

如果需要某个branch的代码,用git checkout即可。比如我们刚刚拿了kernel/common.get的代码,那就先进入到common目录,然后用下面的命令:
git checkout origin/android-goldfish-2.6.27 -b goldfish
这样我们就在本地建立了一个名为goldfish的android-goldfish-2.6.27分支,代码则已经与android-goldgish-2.6.27同步。我们可以通过git branch来列出本地的所有分支。

4、同步版本库
使用epo sync命令,我们把整个Android代码树做同步到本地,同样,我们可以用类似
repo sync project1 project2 …
这样的命令来同步某几个项目

如果是同步Android中的单个项目,只要在项目目录下执行简单的
git pull
即可。

5、通过GitWeb下载代码
另外,如果只是需要主线上某个项目的代码,也可以通过GitWeb下载,在shortlog利用关键字来搜索特定的版本,或者找几个比较新的tag来下载还是很容易的。

Git最初是为Linux内核开发而设计,所以对其他平台的支持并不好,尤其是Windows平台,必须要有Cygwin才可以。现在,得益于msysgit项目,我们已经可以不需要Cygwin而使用Git了。另外,Git Extensions是一个非常好用的Windows Shell扩展,它能与资源管理器紧密集成,甚至提供了Visual Studio插件。它的官方网站上有一分不错的说明文档,感兴趣的朋友可以看一看。


http://source.android.com/source/downloading.html

Downloading the Source Tree
Installing Repo
Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Version Control.

To install, initialize, and configure Repo, follow these steps:

Make sure you have a bin/ directory in your home directory, and that it is included in your path:

$ mkdir ~/bin
$ PATH=~/bin:$PATH

Download the Repo script and ensure it is executable:

$ curl https://android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

The MD5 checksum for repo is bbf05a064c4d184550d71595a662e098

Initializing a Repo client
After installing Repo, set up your client to access the android source repository:

Create an empty directory to hold your working files:

$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.

$ repo init -u git://android.git.kernel.org/platform/manifest.git

To check out a branch other than "master", specify it with -b:

$ repo init -u git://android.git.kernel.org/platform/manifest.git -b froyo

When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.

Getting the files
To pull down files to your working directory from the repositories as specified in the default manifest, run

$ repo sync

The Android source files will be located in your working directory under their project names. The initial sync operation will take several minutes to complete. For more about repo sync and other Repo commands, see Version Control.

Verifying Git Tags
Load the following public key into your GnuPG key database. The key is used to sign annotated tags that represent releases.

$ gpg --import
内容概要:本文详细介绍了C语言指针字符串操作的基础知识与高级技巧。指针部分涵盖了指针作为数据类型的特点,包括指针变量的定义、间接赋值的应用场景及其重要性,以及不同级别的指针如何在函数间传递并修改实参的值。同时强调了指针操作的安全性问题,如不允许向NULL或未知地址拷贝内存,并讲解了`void*`指针的作用及其转换规则。字符串操作部分则重点讨论了字符串初始化、`sizeof`与`strlen`的区别、字符`\0`的作用及其与其他符号的区别,还展示了数组法指针法两种操作字符串的方式,并给出了几个常见的字符串处理算法实例,如统计子串出现次数、去除字符串两端空白字符等。 适用人群:具有初步C语言基础的学习者,特别是对指针字符串操作有进一步需求的编程人员。 使用场景及目标:①帮助读者深入理解指针的工作机制,掌握通过指针间接访问修改内存的技术;②使读者能够熟练运用字符串操作的基本函数,并能编写高效的字符串处理代码;③培养读者的安全意识,避免因不当使用指针而导致程序崩溃或产生未定义行为。 阅读建议:由于指针字符串是C语言中较为复杂的概念,建议读者在学习过程中多做笔记,动手实践书中的示例代码,尤其要注意理解指针间接赋值的原理,以及字符串处理函数的具体实现细节。此外,对于`void*`指针的理解使用,应特别留意其类型转换的要求,确保代码的安全性正确性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值