2011年3月21日 星期一

git

git 真的是一個很強大的分散式版本控制器,用途跟SVN目的有點類似但是功能跟使用方法算是天壤之別。

假如今天我要下載samsung linux 的kernel 在網站看到 git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git

所以可以先將其整個clone到你的local端,

$git clone git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git

這時候他會將全部的歷史資料download到你的.git裡,下載完成後,可以看到資料夾中是/linux-2.6-samsung.git中kernel最後的版本,這時可以透過branch的方式來看有多少remote的分支版本

$git branch -a
2.6.29
2.6.32
*master
remotes/origin/2.6.24-samsung
remotes/origin/2.6.28-samsung
remotes/origin/2.6.29-samsung
remotes/origin/2.6.31-samsung
remotes/origin/2.6.32-samsung
remotes/origin/2.6.35-samsung
remotes/origin/2.6.36-samsung
remotes/origin/HEAD -> origin/master
remotes/origin/master

這時你可以看到remote之後的分支,假設我們現在再主分支master,為此git kernel最新版本2.6.36-samsung,這時想用2.6.24的版本,就透過checkout方式來切換,這地方有點不習慣,因為SVN通常都是一個個資料夾來存取一個版本的方式,git再這邊是多個版本共用一個資料夾,透過checkout的方式可以切換不同版本。

#可以透過tab鍵幫你自動補齊檔案名稱唷~很方便

$git checkout orgin/2.6.24-samsung
Checking out files: 100% (29816/29816), done.
Note: checking out 'origin/2.6.24-samsung'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at b30234a... Official Release(09.08.26)


$git branch -a
* (no branch)
2.6.29
2.6.32
2.6.36
master
remotes/origin/2.6.24-samsung
remotes/origin/2.6.28-samsung
remotes/origin/2.6.29-samsung
remotes/origin/2.6.31-samsung
remotes/origin/2.6.32-samsung
remotes/origin/2.6.35-samsung
remotes/origin/2.6.36-samsung
remotes/origin/HEAD -> origin/master
remotes/origin/master

這時會跑在no branch上,可以透過建立local的branch來存放2.6.24

$git branch 2.6.24
$git checkout 2.6.24

上面兩行合併就為
&git checkout -b 2.6.24

$git branch -a

這時你會看到2.6.24會有*號表示正在使用此branch,你可以多件幾個版本跟隨不同的local branch。


如果不小心建立的不要的branch可以透過下面指令來刪除

$git branch -d [deleted branch name]


大致上git就是這麼神奇,功能如此強大,就是剛開始clone的時間久了一點,因為他將從頭到尾的資料全部塞再.git底下




沒有留言:

張貼留言