Repo/Git 使用手冊, android開發圖說如何使用指令

安裝repo

參考:http://source.android.com/source/downloading.html
1. To install Repo:
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 tool and ensure that it is executable:

$ curl http://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

2.Initializing a Repo client
Create an empty directory to hold your working files.
只有在此目錄底下, 能使用指令repo

$ 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 https://android.googl

Downloading the Android Source Tree
To pull down the Android source tree to your working directory from the repositories as specified in the default manifest, run

$ repo sync

或是 Try using following command, here -c make much lesser time
here -c is used as current branch defined in your manifest. so other data wont get fetched

$ repo sync -c -j5

repo 簡單說明:

其實repo就是用來管理git的工具
所以一定要學會使用 repo forall -c xxxxxxx 這個常用語法結構

#查看所有git狀態
repo forall -c “git status”

#所有git都切換至branch,名稱為”branch_abc”
repo forall -c “git checkout branch_abc”

#查看某個commit的資訊
repo forall -c git log –oneline | grep “commit name”

#上傳修改的部分(類似git push)
repo [–trace] upload

#初始設定repo
repo init -u ssh://@10.xx.xx.xx/opt/git/antares/android/manifest.git -b antares-xxxx –mirror

根據Android Developing提供易上手說明:

(原文版)

基本使用流程:
1. repo sync 先下載程式碼
2. repo start CHECJIN_BRANCH –all 對所有git project建立一個叫 CHECJIN_BRANCH(或其他自取名稱) 的branch
3. 改source code 東改西改, 假設你改了2個git project程式碼
4. 在這2個擬修改的git, 作git commit
5. repo upload (如果出現 # Uncomment the branches to upload: 就把底下的#移除作uncomment吧!)

然後接著 git與repo搭配使用:

—————————-

git 簡單說明:

#Set commiter/creator name/email
git config –global user.name “XXXX”
git config –global user.email “xxxx@xxxxx.com”

#how to use git://xxx/ ?
apt-get install git-daemon-run
vi /etc/sv/git-daemon-run/run
exec git-daemon –verbose –export-all –base-path=$git_path
sv restart git-daemon

#Client
git clone git://$server_ip/project.git

#create a git respository
#create some files
git init

#To visualize branches:
git branch -a

#To create a new branch:
git branch testbranch

# create branch from a commitid
git branch recover_branch commitid

#To change to created branch:
git checkout -b testbranch

#pull data from branch
git pull origin testbranch

#commit created branch name to remote git server
git push origin testbranch

#delete remote branch name
git push origin :testbranch

#To delete a local branch (you need be in other branch to do that):
git branch -D testbranch

#retrieve local deleted file from git server
git checkout file-name

#Track new files:
git add xxxxx.c

#To make a commit:
git commit -a

#To remove the last commit:
git reset –hard HEAD^

# 修改上一次的 commit 訊息
git commit –amend

# 修改將檔案1、檔案2加入上一次的 commit
git commit –amend 檔案1 檔案2…

#Create patches between two branches:
git format-patch master..testbranch

#Create all patch files for changes
git format-patch start-commit-id

#ex: xxx5.1
git format-patch e3d6a36d645fcc210adaf73652295d36cf0c87a1

#reate patches into single file
git format-patch master –stdout > fix_empty_poster.patch

#Check patch
git apply –check fix_empty_poster.patch

#Sign off an applied patch
git am –signoff fix_empty_poster.patch

#abort previous changes ( “previous rebase directory .git/rebase-apply still exists but mbox given” )
git am –abort

#Apply patch & update creator to myself
git apply –index
git commit

#create a tag
git tag -a -m “tagging version 1.0″ v1.0

#push tag
git push –tags

#You can also push a single tag:
git push origin tag name-of-tag

# rename new tag and push it
$> git tag new_tag old_tag
$> git push –tags

#Then delete the tag ‘12345’ from remote and local
git tag -d 12345
git push origin :refs/tags/12345

#//clone from remote git server
git clone ssh://example.com/var/cache/git/project_name.git
cd project_name
touch index.html
git add index.html
git commit -m ‘init’
git push origin master # local 預設 clone 是 master, push 到 origin(remote server)

# Create the remote branch
git push origin origin:refs/heads/new_feature_name

# reverse list
git diff $(git rev-list -n1 –before=”1 day ago” master)

# 手動 merge master commit to RELEASE branch
git checkout master
git pull
git format-patch start-commit-id
git checkout RELEASE (first time: git checkout -b RELEASE )
git pull origin RELEASE
git apply –check 0008-xxx.patch
git am –signoff 0008-xxx.patch
git push origin RELEASE

#Create patches between two branches:
git format-patch master..testbranch

#Create all patch files for changes
git format-patch start-commit-id

#ex:
git format-patch e3d6a36d645fcc210adaf73xxxxxx36cf0c87a1

#Create patches into single file
git format-patch master –stdout > fix_empty_poster.patch

#Check patch
git apply –check fix_empty_poster.patch

#Sign off an applied patch
git am –signoff fix_empty_poster.patch

#abort previous changes ( “previous rebase directory .git/rebase-apply still exists but mbox given” )
git am –abort

Git 初學筆記 – 指令操作教學
http://blog.longwin.com.tw/2009/05/git-learn-initial-command-2009/

git: 如何用git-am来合并git format-patch生成的一系列的patch.
http://www.thinksrc.com/2010/04/22/git-am.html

一篇寫得很易懂得git repository:
http://tkg.im.ncue.edu.tw/?p=755

gitweb設定 (on Ubuntu 10.04)
http://blog.xuite.net/yctseng/notes/35220134

超易懂投影片
http://www.slideshare.net/littlebtc/git-5528339

分類: 未分類

在〈Repo/Git 使用手冊, android開發圖說如何使用指令〉中有 4 則留言

  1. 易春木 文章作者回覆

    補充:
    git revert COMIIT_NUM
    git push
    這兩個步驟就會將COMIIT_NUM這個commit移除掉

  2. weiwei 回覆

    你好 我使用的是ubuntu13.10版 在終端機下指令出現此錯誤

    weiwei@weiwei:~/WORKING_DIRECTORY$ repo init -u https://android.googlesource.com/platform/manifest
    /home/weiwei/bin/repo: line 1: syntax error near unexpected token newline'
    /home/weiwei/bin/repo: line 1:

    repo這個指令似乎在man裡也找不到相關說明 請問大大上面出現的問題是什麼呢?

  3. 易春木 文章作者回覆

    需要先下指令PATH=~/bin:$PATH
    詳情請看下方 :
    –錯誤發生—

    處理方式下指令PATH=~/bin:$PATH
    在執行一次即OK

發表迴響