1.repo介紹
Android使用git作為代碼管理工具,開發了gerrit進行代碼稽核以便更好的對代碼進行集中式管理。還開發了repo指令行工具,對git部分指令進行封裝,将百多個git庫有效的組織。
鑒于repo能夠管理多個git庫,針對一個項目需要多個git庫分開管理使用repo就非常友善。如嵌入式項目一般由uboot、kernel、檔案系統rootfs、使用者程式等組成。這裡就以這樣的項目組織來搭建repo伺服器。
├── kernel
│ └── linux-3.5.y
├── rootfs
│ └── rootfs
├── uboot
│ └── uboot-2018.11
└── userdata
└── UartTest
伺服器:192.168.3.5
賬戶:git
2.下載下傳repo
git-repo下載下傳可在伺服器端通過以下任一方式下載下傳。
git clone https://gerrit.googlesource.com/git-repo (谷歌官方源)
git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo (國内清華源)
git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo (國内中科大源)
3.初始化工程和mainifest git倉庫
3.1 初始化項目代碼倉庫 git server端
git@lisongze-virtual-machine:~$ mkdir exynos4412
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/kernel/linux-3.5.y.git
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/uboot/uboot-2018.11.git
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/rootfs/rootfs.git
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/userdata/UartTest.git
git@lisongze-virtual-machine:~$ cd exynos4412/platform/kernel/linux-3.5.y.git
git@lisongze-virtual-machine:~/exynos4412/platform/kernel/linux-3.5.y.git$ git init --bare
已初始化空的 Git 倉庫于 /home/git/exynos4412/platform/kernel/linux-3.5.y.git/
git@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ cd
git@lisongze-virtual-machine:~$ cd exynos4412/platform/uboot/uboot-2018.11.git
git@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ git init --bare
已初始化空的 Git 倉庫于 /home/git/exynos4412/platform/uboot/uboot-2018.11.git/
git@lisongze-virtual-machine:~/exynos4412/platform/uboot/uboot-2018.11.git$ cd
git@lisongze-virtual-machine:~$ cd exynos4412/platform/rootfs/rootfs.git
git@lisongze-virtual-machine:~/exynos4412/platform/rootfs/rootfs.git$ git init --bare
已初始化空的 Git 倉庫于 /home/git/exynos4412/platform/rootfs/rootfs.git/
git@lisongze-virtual-machine:~/exynos4412/platform/rootfs/rootfs.git$ cd
git@lisongze-virtual-machine:~$ cd exynos4412/platform/userdata/UartTest.git
git@lisongze-virtual-machine:~/exynos4412/platform/userdata/UartTest.git$ git init --bare
已初始化空的 Git 倉庫于 /home/git/exynos4412/platform/userdata/UartTest.git/
git@lisongze-virtual-machine:~/exynos4412/platform/userdata/UartTest.git$ cd
3.2 初始化manifest倉庫 git server端
3.2.1 初始化 manifest git server端
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/mainfest.git
git@lisongze-virtual-machine:~$ cd
git@lisongze-virtual-machine:~/exynos4412/platform/mainfest.git$ git init --bare
已初始化空的 Git 倉庫于 /home/git/exynos4412/platform/mainfest.git/
3.2.2 mainfest 送出default.xml
git@lisongze-virtual-machine:~/exynos4412$ git clone [email protected]:~/exynos4412/platform/mainfest.git
正克隆到 'mainfest'...
[email protected]'s password:
warning: 您似乎克隆了一個空倉庫。
default.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="linux"
fetch="ssh://192.168.3.5/home/git/exynos4412" />
<default revision="master"
remote="linux"
sync-j="1" />
<project path="kernel/linux-3.5.y" name="platform/kernel/linux-3.5.y" />
<project path="rootfs/rootfs" name="platform/rootfs/rootfs" />
<project path="uboot/uboot-2018.11" name="platform/uboot/uboot-2018.11" />
<project path="userdata/UartTest" name="platform/userdata/UartTest" />
</manifest>
remote name:遠端倉庫名
revision:分支名
git@lisongze-virtual-machine:~/exynos4412/mainfest$ git add default.xml
git@lisongze-virtual-machine:~/exynos4412/mainfest$ git comit -m "add default.xml"
git@lisongze-virtual-machine:~/exynos4412/mainfest$ git push origin mster
3.3 用戶端git送出初始代碼
在用戶端 192.168.3.xxx源碼工程下送出初始代碼推送到遠端伺服器下對應的git倉庫。
//在exynos4412/kernel/linux-3.5.y下執行
$ git init
$ git add .
$ git commit -m "Init Code"
$ git push [email protected]:/home/git/exynos4412/platform/kernel/linux-3.5.y.git master
//在exynos4412/rootfs/rootfs下執行
$ git init
$ git add .
$ git commit -m "Init Code"
$ git push [email protected]:/home/git/exynos4412/platform/rootfs/rootfs.git master
//在exynos4412/uboot/uboot-2018.11下執行
$ git init
$ git add .
$ git commit -m "Init Code"
$ git push [email protected]:/home/git/exynos4412/platform/uboot/uboot-2018.11.git master
//在exynos4412/exynos4412/userdata/UartTest下執行
$ git init
$ git add .
$ git commit -m "Init Code"
$ git push [email protected]:/home/git/exynos4412/platform/userdata/UartTest.git master
4. repo拉取工程代碼
在用戶端上repo拉取伺服器端代碼
repo 需要從git-repo源碼中拷貝過來,修改url并加上執行權限chmod 777 repo。
将REPO_URL = ‘https://gerrit.googlesource.com/git-repo’ 修改為 REPO_URL = ‘ssh://192.168.3.5/home/git/tools/git-repo’
如有fatal: branch ‘stable’ has not been signed報錯,可将REPO_REV = ‘stable’ 改為 REPO_REV = ‘master’,或着可在git-repo源碼中切換到stable分支,git check -b state remote/origin/stable,也可重新擷取state分支 git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -b state
$ mkdir exynos4412_code
$ cd exynos4412_code
$ ./repo init -u [email protected]:/home/git/exynos4412/platform/manifest.git
$ ./repo sync
5. repo建立分支
在項目中我們經常會基于某分支建立分支,來開發新的項目。這裡我們示範基于master分支建立tiny4412_evb新分支。
5.1 用戶端建立分支并推送遠端倉庫
./repo forall -pv -c "git checkout remotes/m/master -B tiny4412_evb"
./repo forall -pv -c "git push linux tiny4412_evb"
推送遠端倉庫
git push [remote-name] [branch-name]
remote-name:遠端倉庫名(一般預設遠端分支名稱為origin)
branch-name: 分支名稱
這裡遠端分支為linux,是由于在default.xml中定義的。
其中會報兩個錯誤,是由于沒有權限導緻,如下
error: unpack failed: unable to create temporary object directory
remote: error: cannot lock ref ‘refs/heads/tiny4412_evb’: 不能建立 '/home/git/exynos4412/platform/
解決方法比較暴力,到對應的git伺服器端chmod 777 -R object 和 chmod 777 -R refs
5.2 修改遠端服務端manifest
git@lisongze-virtual-machine:~/exynos4412/manifest$ git branch -a
* master
remotes/origin/master
git@lisongze-virtual-machine:~/exynos4412/manifest$ git checkout -b tiny4412_evb remotes/origin/master
分支 'tiny4412_evb' 設定為跟蹤來自 'origin' 的遠端分支 'master'。
切換到一個新分支 'tiny4412_evb'
git@lisongze-virtual-machine:~/exynos4412/manifest$ vim default.xml
git@lisongze-virtual-machine:~/exynos4412/manifest$ git diff
diff --git a/default.xml b/default.xml
index d1aeaa7..d790a73 100644
--- a/default.xml
+++ b/default.xml
@@ -2,7 +2,7 @@
<manifest>
<remote name="linux"
fetch="ssh://192.168.3.5/home/git/exynos4412" />
- <default revision="master"
+ <default revision="tiny4412_evb"
remote="linux"
sync-j="1" />
git@lisongze-virtual-machine:~/exynos4412/manifest$ git add default.xml
git@lisongze-virtual-machine:~/exynos4412/manifest$ git commit -m "add new branch tiny4412_evb"
[tiny4412_evb 25d1cf6] add new branch tiny4412_evb
1 file changed, 1 insertion(+), 1 deletion(-)
git@lisongze-virtual-machine:~/exynos4412/manifest$ git push origin tiny4412_evb
[email protected]'s password:
對象計數中: 3, 完成.
Delta compression using up to 4 threads.
壓縮對象中: 100% (2/2), 完成.
寫入對象中: 100% (3/3), 293 bytes | 293.00 KiB/s, 完成.
Total 3 (delta 1), reused 0 (delta 0)
To 192.168.3.5:~/exynos4412/platform/manifest.git
* [new branch] tiny4412_evb -> tiny4412_evb
5.3 拉取建立分支代碼
mkdir tiny4412_evb
cd tiny4412_evb
./repo init -u [email protected]:/home/git/exynos4412/platform/manifest.git -b tiny4412_evb
./repo sync
6. 增加子工程git管理
經常我們需要增加一個單獨的子工程需要用git管理,就需要修改遠端伺服器。
6.1 伺服器側操作—建立目錄初始化git server
git@lisongze-virtual-machine:~$ mkdir -p exynos4412/platform/rootfs/tslib.git
git@lisongze-virtual-machine:~$ cd exynos4412/platform/rootfs/tslib.git
git@lisongze-virtual-machine:~$ git init --bare
6.2 用戶端操作-送出代碼
這裡我示例增加rootfs/tslib源碼,在tiny4412_evb分支上。
在tiny4412_evb目錄下操作,拷貝tslib源碼到rootfs下
./repo forall -pv -c "git checkout -b tiny4412_evb remotes/linux/tiny4412_evb"
cd rootfs/tslib/
git init
git add .
git commit -m "add tslib code"
git branch tiny4412_evb
git checkout tiny4412_evb
git push [email protected]:/home/git/exynos4412/platform/rootfs/tslib.git tiny4412_evb
6.3 伺服器側操作-修改manifest
git@lisongze-virtual-machine:git checkout -B tiny4412_evb remotes/origin/tiny4412_evb
git@lisongze-virtual-machine:~/exynos4412/manifest$ git branch
master
* tiny4412_evb
git@lisongze-virtual-machine:~/exynos4412/manifest$ git diff
diff --git a/default.xml b/default.xml
index d790a73..9cb1d41 100644
--- a/default.xml
+++ b/default.xml
@@ -8,6 +8,7 @@
<project path="kernel/linux-3.5.y" name="platform/kernel/linux-3.5.y" />
<project path="rootfs/rootfs" name="platform/rootfs/rootfs" />
+ <project path="rootfs/tslib" name="platform/rootfs/tslib" />
<project path="uboot/uboot-2018.11" name="platform/uboot/uboot-2018.11" />
<project path="userdata/UartTest" name="platform/userdata/UartTest" />
git@lisongze-virtual-machine:~/exynos4412/manifest$ git add default.xml
git@lisongze-virtual-machine:~/exynos4412/manifest$ git status
位于分支 tiny4412_evb
您的分支與上遊分支 'origin/tiny4412_evb' 一緻。
要送出的變更:
(使用 "git reset HEAD <檔案>..." 以取消暫存)
修改: default.xml
git@lisongze-virtual-machine:~/exynos4412/manifest$ git commit -m "add tslib"
[tiny4412_evb 740d86f] add tslib
1 file changed, 1 insertion(+)
git@lisongze-virtual-machine:~/exynos4412/manifest$ git push origin tiny4412_evb
[email protected]'s password:
對象計數中: 3, 完成.
Delta compression using up to 4 threads.
壓縮對象中: 100% (2/2), 完成.
寫入對象中: 100% (3/3), 307 bytes | 307.00 KiB/s, 完成.
Total 3 (delta 1), reused 0 (delta 0)
To 192.168.3.5:~/exynos4412/platform/manifest.git
25d1cf6..740d86f tiny4412_evb -> tiny4412_evb
送出完驗證
./repo init -u [email protected]:/home/git/exynos4412/platform/manifest.git -b tiny4412_evb
./repo sync
7. 給整個工程打tag标簽
git打tag指令:
git tag –a TAG_NAME -m "add tag TAG_NAME"
./repo sync
./repo forall -pv -c "git tag -a TINY4412_V1.0.0 -m "add tag TINY4412_V1.0.0""
./repo forall -pv -c "git push linux TINY4412_V1.0.0"