• 【转载】Git和Repo扫盲——如何取得Android源代码 .


    ZZ: http://blog.csdn.net/zhjuan/article/details/6248956

     

    1 Git 安装
    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 ,进去以后用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

    如果需要某个branch 的代码,用git checkout 即可。比如我们刚刚拿了kernel/common.get 的代码,那就先进入到common 目录,然后用下面的命令:
    git checkout origin/android-goldfish-2.6.27 -b goldfish

    这样我们就在本地建立了一个名为goldfishandroid-goldfish-2.6.27 分支,代码则已经与android-goldgish-2.6.27 同步。我们可以通过git branch 来列出本地的所有分支。

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

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

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

    6、 git的一些常用命令

    git clone
    git init
    git add
    git commit
    git status
    git log
    git diff                       //已commit的文件跟 未commit文件的区别
    git checkout -- filename 
    git checkout -f                //更新文件到最新的git版本
    git ls-files --stage           //查看暂存区(staging area)里的内容
    git cat-file -p 2d832d67       //查看2d832d67中的具体内容
    git cat-file -t
    git rm --cached filename       //把误添加的文件从暂存区(git add)中移除

    git branch test                //建立新分支test
    git checkout test              //切换到分支test
    git diff test                  //查看主分支和测试分支test之间的差异
    git merge test                 //把分支合并到主分支(master)中
    git branch -d test             //删除分支test
    git branch -D test             //当test没有合并到其他分支时,需此命令强制删除
    git reset --hard
    git的对象名是根据对象的内容生成的SHA1哈希串值,因此内容相同对象名就同,对象名同内容就同。
    .git/refs/heads/master 存有主分支(master)最新提交的“对象名”。

  • 相关阅读:
    LeetCode:2. 两数相加
    LeetCode:1. 两数之和
    property类的使用
    JAVA-数据库连接【转】
    快速将excel数据保存到Oracle数据库中【转】
    Oracle导入excel数据方法汇总[转]
    Maven 系列 一 :Maven 快速入门及简单使用【转】
    Maven 系列 二 :Maven 常用命令,手动创建第一个 Maven 项目【转】
    开源项目导入eclipse的一般步骤[转]
    JavaScript基础---作用域,匿名函数和闭包【转】
  • 原文地址:https://www.cnblogs.com/hengfeng/p/2311292.html
Copyright © 2020-2023  润新知