2011年4月28日 星期四

show latest tag name

用 git tags 會 show 出所有的 tag,
如果只要列出這個 branch 最新的,要用:
git describe
有時候要加上 --tags




ref: http://stackoverflow.com/questions/1404796/how-to-get-the-latest-tag-name-in-current-branch-in-git

2011年4月26日 星期二

git clean

有時候在切換 branch 的時候,會出現這樣的 Error:
Untracked working tree file blah would be overwritten by merge
這是說,在這個 branch 裡,沒有加入 git track 的 file,在要 checkout 的 branch 中,被加入 track 了,所以 checkout barnch 時會有問題。

解決方法就是用
git clean把所有沒有 track 的file 刪掉,就可以 checkout 到另一個 branch。



ref: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull 有時候用 git clean -f 強制刪除所有untrack 的 file.
但是這個命令不會刪除 untrack folder.

要的話,就要用: git clean -f -d 這樣就會把 untracked folder 也刪除。

2011年4月14日 星期四

make an existing git branch track a remote branch

如果當初 就是 checkout remote branch 出來,那個 branch 會自動設定 upstream 是 remote branch.
所以 push, pull 都會對應到 這個 upstream (remote branch)

但是如過自己這個 branch 是 local create,之後卻要設定他的 upstream 是某一個 remote branch 的話..
$ git branch --set-upstream localbranchname remotename/branchname
這樣就可以設定自己這邊的 localbranchname 的 upstream 是 remotename/branchname.


ref : http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch

checkout remote branch , merge then update it.

看一下 remote 的 branch
$git branch -r
korg/master
korg/my9.1
korg/release-1.0
korg/rtk

checkout 出 remote 要merge 的 branch
$git checkout rtk
Branch rtk set up to track remote branch rtk from korg.
Switched to a new branch 'rtk'

這個動作很奇怪,如果原來就有一個 branch 叫 rtk 呢?他怎摩區分我是要 checkout remote 端的 rtk branch, 還是要 checkout 原來的 local rtk branch ?

接著 merge 到我的 code:
$git merge mytest
然後就可以 push 回 remote
$git push
都不用指定remote name...

2011年4月13日 星期三

merge -- just use the target file

merge 得時候 會自動修改 conflict 的 file,並且在 file 裡面 conflict 的地方加上:
>>> HEAD
=====
..

的 mark。

要是merge 時,只是要用 另一個 branch 的 code,並不是真的要 加上 local 跟 branch 的 code。
可以在 merge command 完,再用:
$git checkout --theirs .
$git add -u
$git commit

把 "theirs" 的 code 都checkout 出來 (最後的 '.' 代表全部的 code)
把所有conflict 的 file 都mark 為 resolve (-u)
然後 commit (會自動加上 merge 的 comment

如果是要用原來的 (那 merge 幹麼?) , checkout 時用 option --ours


ref :

delete remote branch

$git push korg :branchname

在 branch name 前面加 ":" 就是刪除

config merge tool

$git config --global merge.tool vimtool
這樣開啟 .gitconfig: 會多了:
[merge]
tool = vimdiff