2011年3月23日 星期三

Reference


internal -- staging area

這一篇說得很清楚 (http://ihower.tw/blog/archives/2591 ).

staging area 是一塊 git 用來紀錄 commit command 要"提交的東西" 的區域)。
所以當你commit 過後,staging area 是空的。
用 git add, 就會把 add 的 file 加到 staging area 裡。

平時用的
$git commit -a a option ,意指..將修改過的檔案add 到 staging area,
所以這樣 commit ,會自動把修改過的 file commit 進去。

要是不加 -a 選項,就要在commit 之前,用 git add 把要 commit 的 file 加到 staging area。
然後 commit 才會 commit這些 file 進去。

要把 staging area 裡的 file 拿出來,用:
$git reset HEAD filename
這樣,那個 file 就會從 staging area 移出來,恢復到還沒被加入 staging area 的狀態 (原來是 untracked 就是 untracked, 是unstaging 就是 unstaging),修改的內容不會消失。

因為有 staging area,所以 diff 分為以下三種:
$git diff
比較 working 跟 staging area

$git diff --cached
拿staging area 的file 跟 HEAD 的內容 (上次commit)比較

$git diff HEAD
比較 working 跟 HEAD 的不同。

2011年3月22日 星期二

merge --squash

git merge 會保留分之的 commit log,所以 merge 之後,主線會留下 分支的 commit log。
所以 merge 完後就可以砍掉分支。不用擔心分支的 commit log 會不見。

但是 git merge 會自動 commit,並且在最後加上一個 "merge" 的 commit log。

如果只是要 merge,不要 commit ,就要用 --squash 這個 option
$ git merge --squash branchname
這樣就 code merge 完就不會作 commit,但是 .. branch 的 commit log 也不會被加到主線來。

加上

2011年3月17日 星期四

diff - show brief

只是要看有哪些檔案不一樣,可以加上 --stat 這個選項
$ git diff 201101270-a2 --stat
這樣就會顯示和 20110127-a2 這個 branch 的差異:
Makefile | 1 +
board/freescale/mx51_bbg/flash_header.S | 24 ++++--
board/freescale/mx51_bbg/lowlevel_init.S | 5 +-
board/freescale/mx51_bbg/mx51_bbg.c | 118 +++++++++++++++++++++++++++---
include/configs/mx51_bbg_android.h | 8 ++-
5 files changed, 132 insertions(+), 24 deletions(-)

2011年3月16日 星期三

git remote -- show branch

列出所有remote target 的 branch
$git branch -r
以有加入charles-robot, origin 兩個 remote target 的 repo 為例,會列出:
charles-robot/201101270-a2
charles-robot/20110131-test-a3
charles-robot/20110132-back-to-a1
charles-robot/20110316-a3-emmc-boot
charles-robot/cv7000-A2
charles-robot/imx_r9.1
charles-robot/master
origin/GPL-Cleanup
origin/HEAD -> origin/master
origin/i.MX31
origin/lwmon5
origin/master
origin/next
origin/origin
origin/tx25
origin/u-boot-2009.11.y

git tag

$ git tag A3-factory 7735517
然後用
$ git tag
就會列出所有的 tag

git log

每個 commit 用一行來顯示
$git log --pretty=oneline
會是:
77355173c615b063d06061b698755d56676671e2 loyal 3G, tony break detect,AudioProcessor,Auron pmic_adc
20caf82ec8774c8a8635bf9679dc559f57fa6f30 commit previous patch
1fd44d644180a3a099c2e899aa1135bc80b00104 commit previous patch
8946a0b7e83f818430417a64eaf8bebdcf3ef64a commit pmic_adc.c
de713684abf9725717b070836333f0cc023ad21f 20110121
72443f571e57059fc44d719e4aedbe83c9b78723 20110121_01
...