2012年10月11日 星期四

Git Tutorial


Git 安裝
  1. Windows
    1. msysgit http://code.google.com/p/msysgit/downloads/list
    2. Tortoisegit http://code.google.com/p/tortoisegit/downloads/list
建議下前者msysgit的Git for Windows


  1. MAC
    1. msysgit Git for OS X http://code.google.com/p/git-osx-installer/
    2. http://git-scm.com/ 可以選擇要不要下GUI的

前者沒用過。

其實Git的工具網路上搜尋很多,但好不好用,有沒有bug,都是問題。
像是,請盡量不要用eGit(Eclipse提供的git),常出問題且版本追溯的功能不大好。

ME
在Windows上目前是使用Git for Windows的Git Bash,
而在MAC的是git-scm裡面的GUI版本,
但GUI版本只能做到簡單的pull、add、commit、push(他的 pull+push == sync),
所以我會配合command line使用。



Git 設定 [Optional]

  1. SSH Key
可參考下面這個網址「Git 設定」的部份,這個部分是Optional的

功用:
不用每次git push都輸入一次GitHub的帳號密碼,等於帳號綁定device,從綁定的device推都認定是這個帳號,從而去判斷有沒有權限git push。

ME
在Windows上有用,因為那時還不太懂照著別人教的做。
在MAC上沒有用,因為覺得不過是多打一次帳號密碼,而且是公司電腦...

  1. git config --global color.status auto git status時有顏色,較容易看。

還有一些其他的設定可以玩,有興趣可以Google一下。


Git 常用指令
git pull 把GitHub上面最新的拉下來
git add . 把目前資料夾底下所有有更動的(不包括deleted file)的file加到觀察中
git add -A . 同上,但包括deleted file
git add file_name 把file加到觀察中
git commit -m "Comment" 加上這一次更動的comment
git push 把這批更動過的file推上GitHub
git status 看有哪些檔案更動過(changed/new/delete)


Git 次常用指令
git log 看history和commit id
git reset file_name 把git add過但還沒git commit的file取消add
git revert commit_id 取消commit
git diff 看更動過的部分(所有更動過的檔案都會有)
git checkout xxx ...要用再去查吧...有很多種用法


Git 應用入門
我們TicketToe目前在https://github.com/Clique/TicketToe
只要登入就可以從左上角那邊選自己或者Clique。

只有第一次copy repository到local要做 git clone https://github.com/Clique/TicketToe.git
p.s.不用幫他新建資料夾

之後每次code有更動就只要到 TicketToe/ 底下做
  1. git pull
  2. git add .
  3. git commit -m "Comment"
    (2+3: git add . && git commit -m "Comment")
  4. git push

如果有刪檔案,做
  1. git pull
  2. git add -A .
  3. git commit -m "Comment"
    (2+3: git add -A . && git commit -m "Comment")
  4. git push



如果在push的時候出現conflicts做
  1. 打開他說conflicts的檔案,裡面conflicts的地方會長得像
    <<<<<<< HEAD
    Original content in GitHub
    =======
    Changes you made
    >>>>>>> xxxxxxxxxxx
    處理修改過後存檔
  2. git add .
  3. git comment -m "Comment"
  4. git push


關於TicketToe
  1. 從command line進入TicketToe/demo/
  2. 打 rails s 啟動server
  3. 用瀏覽器打開目前的首頁 http://localhost:3000/tickets/

進階

沒有留言:

張貼留言