2012年4月28日 星期六

git 筆記

git add, rm, commit, clone, fetch, reset, checkout 比較基本,應該不用記。
目前使用的 git 版本是 1.7.9,不一定每個版本都一樣!


checkout 某個 commit 出來 build
> git archive --format=tar --remote=repository_location commit_id | tar xvf -

不用 commit 拿 commit ID
把改過的檔案先放到 stage
> git add files
建立 tree object 就會出現 commit ID 啦
> git write-tree

從其他 branch 抓 commit 進來
> git cherry-pick commit_id
其實也蠻常用 branch~加數字:0 是 HEAD, 1 是 HEAD^ 以此類推
> git cherry-pick some_branch_name~0


比較兩個 tree
> git diff-tree -p branch1 branch2


看某一檔案每一行的 commit 紀錄
> git blame somefile.c


merge branch1 到 branch2
> git merge branch1 branch2


送 patch 到 mailing list
產生 commitA 到 commitB 的 patch 檔和 cover letter
> git format-patch --cover-letter -n commitA..commitB
寄 patch 出去
> git send-email --smtp-server yourserver --from whoareyou@mail.server.com --to mailing@list


從 mbox apply patch
> git am -3 -i -s -u patch.mbox
-3 是嘗試用 3-way merge
-i 是 interactively
-s 跟平常一樣是 signoff
-u 是 utf8


調整 commit 順序等
> git rebase -i commit_id
會跳出 editor 讓你調整 commit,例如:


pick e29ad97 Blackfin: cache result of cpp check
pick 042f9f1 gpio: Adapt PCA9698 to standard GPIO API
pick bd25fdb Makefile: Add the missing dependency for spl target


並提示:

# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
把上面的 pick 換成你想要做的事情,當然也可以調整 pick 順序,例如:


r 042f9f1 gpio: Adapt PCA9698 to standard GPIO API

e e29ad97 Blackfin: cache result of cpp check
pick bd25fdb Makefile: Add the missing dependency for spl target
存檔離開之後,git 會從上而下 pick 進原本的 branch。
其實上面作用跟 checkout 出一個 branch 到 042f9f1~1,然後再一個一個 cherry-pick 進來差不多。




我最常用的就是 fixup... 因為常常打錯字或者放到空白orz

沒有留言: