Cheat sheets of git and repo
一般跟別人合作開發都是使用 git。那 repo 是什麼? repo 是 Google 開發出來的工具,用來管理 Android 的。 這篇文章會列出常用的指令。
一份 Android code 是由許多 project 組成的,每個 project 就是一個 git project。 repo 這個工具,就是可以管理 branches 以及眾多的 git project! > repo init 後,可以找到 .repo/manifest.xml 這會記錄你控制的 projects
*基本工作流程與對照:
repo | git |
repo init -u URL -m ooxx.xml -b remote_branch | git clone URL |
repo sync -c | git pull URL remote_branch:local_branch |
repo start branch_name –all | git branch branch_name |
git status | git status |
git add | git add |
git commit | git commit |
repo upload . | git push |
*git 好用指令: > 新增一個 local branch git branch {name} > 切換 branch 到 另一個 branch’ git checkout {branch’} > 刪除特定 local branch git branch -d {name} > 查詢遠端的server 位置及名字 git remote -v > 新增一個遠短 server git remote add {given_name} URL > 強迫 reset git reset –hard {local_sha} > 把 commit 推到遠端 branch git push {given_name} {local_branch}: refs/for/{remote_branch} > 從遠端 branch 拉 code 下來 git pull {given_name} {remote_branch}:{local_branch} > 當前一個修改已 commit,又想把這次修改跟上一個修改一起 commit git commit –amend > 想上 patch 到某個已經 push 出去的 change git push {given_name} {local_branch}:refs/changes/{change_id} > 查詢某行的歷史 git blame -L [行數] [檔案名] > 撿別 branch 的 commit 到目前的 branch git cherry-pick [sha-1] > output a beautiful format git log –pretty=format:”%h,%ae,%ar,%s”
*好用的配置 > git commit 的模板: 新增一個 ~/.git-template 然後 git config commit.template ~/.git-template
> 設置reviewers, git push rest,就會自動帶上 reviewers 到 .git/config 編輯 [remote “test”] pushurl = ssh://account@server_address:port/project_name push = {local_branch}:refs/for/{remote_branch}%r=someone1@mail, r=someone2@mail
*製作 patch,打 patch (在 branch A) git log git format-patch -1 [sha-1] mv ooxx.patch ~/ (換到 branch B) git am [~/ooxx.patch]
*合併 commits / 分支 git rebase -i {要固定住的那個 git log} [modify rebase script] https://zerodie.github.io/blog/2012/01/19/git-rebase-i/
*把特定檔案還原到指定的 git log 時期的樣子 git checkout {指定的 git log} {file name}
*如果沒有圖形化介面的 gitk,可用 git log –oneline –graph
*查看現在 local branch 是從哪的 remote 抓來的 cat .git/FETCH_HEAD*所有的 git log .git/logs
值得注意的是: pull 的 server / review 的 server / push 的 server 可能不同, 設置 push 的 server 時,請去確認 repo upload 時,到底是推到哪?
Last updated