git

command note

Commit 管理

git revert xxxx 用新的 commit 來退版
git checkout -- <file\> 將檔案內容向前還原
git reset HEAD <file\> 變更檔案狀態
git reset --soft HEAD^ 撤銷最近的 commit
git commit --amend 修改 commit 訊息

git log --pretty=oneline

Remote

git fetch
git merge origin/<remote-branch>

.gitignore

* matches anything except a slash.
? matches any one character except /.
** can match directories anywhere.

A convenient .gitignore in Linux :

*
!/**/
!*.*
!/**/makefile
!makefile

開發相關

jserv's opinion

  • 程式註解:幫助理解程式碼行為
  • git commit message:幫助追溯程式、專案開發軌跡
  • HackMD documentation:開發流水帳及問題記載、如何克服

Way to Write Good git Commit

source:

How to Write a Git Commit Message
如何寫好 git message

The seven rules

  1. 用一行空白分隔標題和 body
  2. 標題保持在 50 個字元以內
  3. 標題開頭大寫
  4. 標題不加句號
  5. 以祈使句撰寫標題
  6. message body 每 72 字元就要換行
  7. 使用 body 去解釋為何要這麼做

commit message 是為了幫助開發者掌握程式碼變更的脈絡(原因)而非變更內容

標題部份

  • 如果無法保持在 50 個字元以內,那麼或許這個 commit 的變更太多了
  • 一個良好的 commit 應該適用於以下模板

If applied, this commit will <標題>.

body部份

  • 解釋 commit 解決了什麼問題,集中描述為何要這麼做而非如何達成,描寫這個變更帶來了什麼不直覺的結果
  • 如果有 issue tracker 可以放在最後