GIT 使用



公司要求要做 version controll 很久了。
也導入了 GIT ,但嫌麻煩,一直沒用。不過,還是逃不了。
當然,它是很不錯的工具。會用是一件好事,可以增長見識。

不免俗的介紹一下何謂:GIT
Git 是
Linus Torvalds 寫的, 也就是寫企鵝系統 Linux 的那個。 你可以看看他 介紹 Git 的影片。 裡面一直說用 Subversion 的人很笨,所以他聽起來有點沒水準。 世上的人不可能每個人都像他那麼聰明吧? Linux 的版本管理就是用 Git 的喔, 所以 Git 也很適合超大型的檔案版本管理。 Git 很快也很省空間。 它利用分散式的管理方法, 也就是說每個人下載的版本裡有包含有史以來更改過的紀錄。 沒有一個人的版本是主要的版本, 你喜歡把自己的版本怎麼改就怎麼改, 那你喜歡接受任何人的更改就接受人和人的更改。 這樣來說,不就天下大亂? Linus 說不會, 因為他只接收他信任的人的修改, 不會隨便去跟阿貓阿狗的程式碼合併。 而他信任的人也同樣的只會接受他們信任的人的修改, 依此類推。

GIT 功能太多,我也不想那麼瞭解。夠用就好。先貼一下 command 介紹。

$ git init
# 開始用 Git 來管理
$ git add .
# 把所有檔案加入 Git
$ git commit -a
# 做成一個版本
$ git commit -a -m "your message here"
# commit 時直接寫訊息, 不用到下個螢幕上寫
$ git tag v0.02
# 本版別名取為 v0.02
$ git tag v0.03 40e3e
# 把版本 40e3e 取名為 v0.03;
$ git status
# 查詢從上個版本到現在哪些檔案被修改
$ git diff
# 查詢從上個版本到現在哪幾行被修改
$ git diff v0.01 v0.03
# 查詢兩個版本間的差異
$ git diff v0.01:story.txt v0.03:story.txt
# 查詢兩個版本間某個檔案的差異
$ git log
# 查詢有史以來哪幾個檔案被修改
$ git log -p
# 查詢有史以來哪幾行被修改
$ git log --stat --summary
# 查詢每個版本間變動的檔案跟行數
$ git show v1.01
# 查詢 v1.01 版裡的修改內容
$ git show v1.01:story.txt
# 叫出在 v1.01 版時的 story.txt 檔案
$ git show v1.01:story.txt > test.txt
# 把 v1.01 版的 story.txt 抓出來,放入一個叫 test.txt 的檔案
$ git show HEAD
# 看此版本修改的資料
$ git show HEAD^
# 看此版本前一版的修改的資料
$ git show HEAD^^
# 看此版本前前一版的修改的資料
$ git show HEAD~4
# 看此版本前前前前一版的修改的資料
$ gitk
# 版本瀏覽軟體, GUI
$ git gui
# 瀏覽從上一版本到現在變動的地方; 沒辦法顯示中文
下列就我用到的部份。整理一下。
--- Remote 端建好progect ,但還沒上傳。
1. mkdir 目錄
// 建好目錄。
2. git init
// initial 完後,並將檔案放入
3. git add .
// 將檔案加入git
4. $ git remote add origin [remote repository.git]
// remote add告訴 GIT 我的 source code 要上傳到哪裡去
// ex: git remote add origin git@10.1.2.212:RD3/C2CSA_Main.git
5. $ git commit -m "註解" -a
6. $ git tag v0.10 XXXX
// 建立 tag
7. $ git push origin master --tags
// 上傳

------------------------------------------------------------------------------
$ git remote -v
// 可以看 remote repository.git
$ git remote rm origin
// 如果 remote repository.git 設錯。可以用 rm 殺掉
------------------------------------------------------------------------------

--- Remote 已有project,複製到 local 端,再做 sync
1. git clone -v [remote repository.git] checkout
// 將 project 下載 checkout 目錄
2. 將修改和新增的檔案放入
3. git add .
4. git commit -a -m "註解"
5. git log
// 查看 LOG
6. git push origin master --tags
// 上傳



--- Remote 已有project,下載 git server 上新的版本
1. git pull origin master // 下載 master 版本
2. git reset --hard                     // 回覆的上次下載的 master 版本

Reference :
1.
http://www.qweruiop.org/nchcrails/posts/49

留言

這個網誌中的熱門文章

NMEA標準格式 -- GPS

網路 Transformer 的用途

cut,sed,awk 字串處理