這裏主要介紹嵌入式開發中常用的技術。
代碼管理
git
代碼結構樣例
$ tree -a -L 2
.
├── .git
│ ├── branches
│ ├── COMMIT_EDITMSG
│ ├── config
│ ├── description
│ ├── FETCH_HEAD
│ ├── HEAD
│ ├── hooks
│ ├── index
│ ├── info
│ ├── logs
│ ├── objects
│ ├── ORIG_HEAD
│ ├── packed-refs
│ └── refs
└── release
└── apollo
9 directories, 8 files
Git工作流程大致如下:
代碼清理(reset&clean)
清除未提交的本地工作
$git reset --hard
$git clean -xdf
或
$rm -rf *
$ls -a
.git
$git reset --hard
關於 git reset
This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree
-
git reset --soft
: 不會更新index內容,也不會更新工作目錄(退至特定的commit,但是保持staged與工作目錄不變)。 -
git reset --hard
: 同時更新index內容和工作目錄(比如退至特定的commit,同時工作目錄也做相應更新)。 -
git reset [--mixed]
: 更新index內容,但是不更新工作目錄內容(比如將log看到的已經被commit的提交,變成staged的狀態)。
提交與拉取、推送(commit,pull&push)
$git pull
$git pull --rebase
$git commit -a -m 'xxx'
$git add/rm
$git commit -m 'xxx'
$git commit --amend
$git push origin HEAD:refs/for/2K18_UI_FFC_tpv
$git push origin HEAD:refs/for/2K18_UI_FFC_tpv%[email protected],[email protected]
分支與合併(branch,merge,checkout)
相關命令如下:
$git branch [-l]
$git branch -r
$git branch -a
$git branch <name> [<start>]
$git checkout -b <name> [<start>]
$git merge <branch>
$git cherrypick <commit id>
關於期間分支的變化情況,可參考: man git rebase
others
$git checkout <file>
$git blame <file>
$git log
$git log --graph
$git log --author=<pattern>
$git status
$git format-patch <start>
repo
代碼結構
$ tree -L 2 -a
.
├── android
│ └── n-base
├── apollo
│ ├── custom
│ ├── linux_core
│ ├── linux_mts
│ ├── middleware
│ ├── mtk_obj
│ ├── oss
│ ├── sys_build
│ ├── target
│ ├── third_party
│ └── tools
└── .repo
├── manifests
├── manifests.git
├── manifest.xml -> manifests/default.xml
├── project.list
├── project-objects
├── projects
├── repo
└── .repo_fetchtimes.json
19 directories, 3 files
初始化本地代碼庫
初始化主要是針對manifest與repo項目
repo init
--mirror
--reference <mirrorpath>
-u <remote url>
-b <repo branch>
舉例:
#創建可被其它本地repo倉庫引用的緩存鏡像
$repo init -u ssh://url/tpv/platform/manifest -b 2k18_mtk_msaf_kane_n_devprod --mirror
#通過引用緩存鏡像縮短下載整個代碼倉庫的時間減少項目佔用空間
$repo init -u ssh://url/xxx -b xxx --reference xxx
#普通的初始化方式
$repo init -u ssh://url/xxx -b xxx
$repo init
注意:通過 mirror
指定的鏡像緩存,可以減少下載代碼的時間,並減少項目佔用的空間。
代碼同步與清理
主要通過 repo sync
來實現
舉例:
#刪除工作目錄(保留.repo目錄)
$rm -rf && ls -ap
.repo/
#從.repo恢復工作目錄(不聯網下載)
$repo sync -l
#從.repo獲得所有工作目錄並與遠端更新
$repo sync
$repo sync -j4
#從.repo獲得當前工作目錄並與遠端更新
$repo sync .
其它
其它命令參見 repo --help
$repo forall -c "git xxx"
$repo info