iOS App 開發團隊使用 Gerrit 進行程式碼審查。以下說明假設你使用的是較新版本的 Mac OS X。
本文依序涵蓋:初次使用 Git、啟用審查帳號、把程式碼取回本機、提出修改並申請審查、更新你的程式碼、Gerrit 因合併衝突而無法送出時的處理、程式跑不起來時的排查,以及一組 Git 實用技巧。
如果你是 Git 新手,建議先讀官方 Git 書的前三章,這會讓後續省下不少力氣。就算現在不讀,至少等到被 Git 折磨得夠嗆時再回頭看。另外可參考 Gerrit Code Review 工具的簡介,並遵循團隊制定的 Common Workflow,以避免常見的坑。
git clone https://tech.lds.org/mobile/codereview/p/PROJECT
cd PROJECT git submodule update --init --recursive
curl https://tech.lds.org/mobile/codereview/tools/hooks/commit-msg > .git/hooks/commit-msg chmod u+x .git/hooks/commit-msg
git config remote.origin.push HEAD:refs/for/master
git config --global user.name "Your Name" git config --global user.email "your@email.address"若已經用錯誤的資訊提交過,可以:
git commit --amend --author="Author Name <email@address.com>"若有多個 commit 資訊都錯了,就得走更深入的處理步驟。
git checkout master
git pull origin master
git checkout -b <branchname>
git diff git status
git commit -a系統會要求輸入 commit message,建議格式如下:
(PROJECT-245) Short summary of change (~50 chars max, issue ID in parentheses if applicable) A more elaborate summary of the committed changes and suggested tests. May have bullet points or paragraphs. Break at 72 chars. This is shown when users view the full commit.
git push會詢問使用者名稱(LDS Account)與密碼,建議設定 git 憑證快取以免每次都要輸入。
審查流程的目的在維持程式碼品質、確保每一行都有超過一組眼睛看過,並讓貢獻者與審查者彼此學習。幾乎每個審查都會要求做一些調整,即使只是小改。遇到這種情況:
git diff git status
git commit -a --amend git push
送出變更時若出現「Your change could not be merged due to a path conflict」,請依下列步驟解決:
許多建置與執行問題可以靠下列其中一項或全部解決:
git rebase -i HEAD~3(是 dash i 加 tilde 3)
pick f7f3f6d changed my name a bit s 310154e updated README formatting and added blame s a5f4a0d added cat-file
:wq
警告:這會失去所有未提交或未 stash 的修改。
要徹底丟掉,執行 git reset --hard HEAD;若只想暫時收起來,用 git stash。
警告:這些步驟會清掉你在該分支上所有未發布的修改,即使已經 commit 到該分支也一樣(若已 commit 到別的分支或有 stash 則不受影響,但仍請小心)。
git config --global diff.tool opendiff
git config --global merge.tool opendiff
mergetool 預設會保留 ".orig" 備份檔,若想關閉可執行 git config --global mergetool.keepBackup false。
本頁最後修改於 2013 年 12 月 4 日 15:15,累計瀏覽 6,903 次。