2015年1月22日 星期四

2015.01.22 GitHub課程

git是甚麼?
一個版本控制系統
彙整-如何將一個新的專案上傳到github中?

  1. 至github中新增一個repository,新增完之後會有一個網址,這個網址待會會用到
  2. 在終端機先執行「git config --global user.name "sunny" 」設定user name和「git config --global user.email sunnylee320@gmail.com 」設定user email
  3. 設定好基本資料之後,切換到專案資料夾下,執行「git init 」將目前的資料初始化成可以被git版本控制的資料夾
  4. 「git add --all 」將所有檔案加進git暫存區
  5. 「git commit -m 'init commit' 」將暫存區的檔案儲存進repository中
  6. commit之後執行,origin後面的連結就是放之前在github網站中新增repository得到的網址「git remote add origin https://github.com/sunnylee320/rubyjob2.git 」
  7. 「git push -u origin master」按照指示輸入github的Username和Password
  8. 完成~

which git 查看git安裝在哪
git --version 查看git的版本
git config --list 目前的設定
git config --global user.name "sunny" 設定user name
git config --global user.email sunnylee320@gmail.com 設定user email
git clone https://github.com/kaochenlong/eddie-vim.git 將遠端檔案複製到本機
在/eddie-vim(git版本控制的資料夾)下執行 git log查看紀錄
在git log中要離開 按下 q

mkdir gitdemo 建立gitdemo資料夾
cd gitdemo/ 切換到gitdemo資料夾
git init 將目前的資料初始化成可以被git版本控制的資料夾

ls -al 將目前資料夾下所有的資料夾列出詳細資料(包含隱藏檔)
ls將目前資料夾下所有的檔案列出(不包含隱藏檔)
touch hello.rb 建立hello.rb檔案
git status git的working directory、staging area目前狀態
git add hello.rb world.rb 將這2個檔案加進git暫存區
git add --all 將所有檔案加進git暫存區(staging area)
git rm --cached hello.rb 將hello.rb移出暫存區(移至working directory)
git commit -m 'init commit' 將暫存區的檔案儲存進repository中, -m 'message ' 中間是描述這次儲存的訊息(顯示在git log中)

nano hello.rbv      使用nano編輯器編輯hello.rb
再使用git status查看狀態,就會看見hello.rb被放在工作區
此時有2種選擇:git add 新增至暫存區、git checkout 取消此次更動
commit時機:工作告一段落、commit訊息很重要時

git commit --amend 修改最後一次的commit訊息

rm hello.rb                      刪除hello.rb
git checkout hello.rb      回復hello.rb這個檔案(前提是檔案已經commit)


如果專案要新增一個功能,使用git開啟支線(branch),在支線完成新功能,確定沒問題後再與主線合併(merge)
git branch                                   目前在哪個分支、有哪些分支
git branch member_branch        新增member_system分支
git checkout member_system    移到member-system分支
git merge member_system          合併member_system分支(併到master中)
git branch -D member_system     將member_system分支刪除

將本機端檔案新增至遠端github帳號中:
git push -u origin master (master可替換成其他要新增的分支) 
至github中觀看
到其他地方要編輯專案,使用git clone https://github.com/sunnylee320/0122github.git
(git clone後的網址是git專案的網址在網頁右邊HTTPS中)
專案在本機編輯好後使用 git push origin master將最新的檔案上傳到遠端github
git pull 將目前遠端github最新的檔案下載至本機端
如果本機端的檔案是最新的會顯示「Already up-to-date」

如何在GitHub上取得別人的專案?
在要複製的專案頁面按下Fork
 在自己的GitHub中即可看見該專案
將分支專案中改好的檔案推薦給原作者