用户名: 密码: 忘记密码? 注册

玩转repo_git

作者:  时间: 2010-11-09
首先:安装git
sudo apt-get install git-core curl

然后安装repo:

1.curl http://android.git.kernel.org/repo > /bin/repo

chmod a+x /bin/repo

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


2.如果做到这一步的时候出现repo: command not found。
后来经过多方面查找才发现还须要设置。方法如下。
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
export PATH=$PATH:$HOME/bin

3. repo sync
如果上面没问题,执行同步即可拷下全部代码。

如果想拿某个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插件。它的官方网站上有一分不错的说 明文档,感兴趣的朋友可以看一看。


6.repo help
xxh@xxh-laptop:~/android/prebuilt$ repo help
usage: repo COMMAND [ARGS]

The most commonly used repo commands are:

  abandon    Permanently abandon a development branch
  branches   View current topic branches
  checkout   Checkout a branch for development
  diff       Show changes between commit and working tree
  download   Download and checkout a change
  grep       Print lines matching a pattern
  init       Initialize repo in the current directory
  prune      Prune (delete) already merged topics
  rebase     Rebase local branches on upstream branch
  smartsync  Update working tree to the latest known good revision
  stage      Stage file(s) for commit
  start      Start a new branch for development
  status     Show the working tree status
  sync       Update working tree to the latest revision
  upload     Upload changes for code review

See 'repo help <command>' for more information on a specific command.
See 'repo help --all' for a complete list of recognized commands.

7.git help

xxh@xxh-laptop:~/android/sdk$ git help
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
           [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help COMMAND' for more information on a specific command.