2014年10月30日 星期四

Git 常用指令 Par1

Git 常用指令

git clone後的檔案下先在每個資料夾建立master,指令如下

repo start master --all

repo forall -c "git checkout branch_abc"  將所有git都切換至branch_abc

其實repo是用來管理git工具,repo forall -c  xxxx意思為對所有下指令

repo status   檢查當下每個資料夾下有建master,看當前的branch為何

git status : 檢查當前狀態,有哪些檔案被更改過

git pull :拉看看server端有無更新,此動作建議在master進行,使master保持最新的source。

git push :在master branch建議不要做任何修改,保持一個乾淨的狀態,建立 而外的branch,在新的branch只要做每一次的commit行為要注意。
你做的每個紀錄都會上傳到server

git add  filename : 加入檔案後面在加檔案名稱

ex: git add my.c

當加入的git file是預設忽略的,可先執行以下指令查看
git status --ignored

若要加入追蹤可下此指令
git add -f filename :  -f為強制加入ignored檔案

git commit -a -m "message" : 將改好的檔案commit上去,但新增的檔案還需要執行git add 加上才可行

git init : 初始化git

git rm filename : 刪除檔案並取消追蹤

git rm --cached filename : 刪除追蹤檔案,但此檔案要先commit在git上

ex: git add my.c
      git commit -a -m "test"
      git rm --cached my.c

git checkout -b brach_name : 建立新的branch並切換過去

git branch : 查看當前的branch狀態,並以*顯示你在哪個branch

git branch -r : 列出所有Repository branch

git branch -a : 列出所有branch

git reset --hard HEAD~1  : 此指令會回到上一個commit的狀態,檔案也會還   原,故在使用時須要小心,可配合git commit log來看commit的使用狀態

ex:
首先要用git log來找出序號編碼(b02f4d370488...),然後選擇你要回去的哪個commit狀態

git reset --hard xxxxxxxxxxxxxxxxxxxx : xxxx..處填寫序號編碼

git log -2  : 列出最近兩筆的log

git diff     :列出與上次修改不同的地方

git diff xxxxxxxxxxxxxx : xxx之處填git log給的一組序號編,例如:b02f4d370488....可以看到上次更改的地方

git diff branch1 branch2 : 列出branch1與branch2的差別(修改過的地方)。

git diff branch1 branch2 --files :列出branch1與branch2的檔案差別

git diff -- files : 比較當前工作目錄下(尚未加入索引staged)與上次commit的檔案差異

git diff --cached --files :比較當前工作目錄下(已加入索引staged)和上次commit的差異

git diff HEAD -- files : 比較當前工作目錄下的檔案(不管是否加入所以staged)和上次commit的差異


Patch的使用
1.apply patch
首先產生新branch並指到最新code base
git checkout -b abc  -b fdc/xxxxx  
   abc為branch
   fdc/xxxx為哪個code base (branch -r 可查詢)

git pull  看看有無更新code
git apply --reject xxxxx/00001xxx.patch             xxxx為patch的路徑與檔案
git status  最後檢查看有無產生.rej檔

or
git am xxxx/0001xxx.patch


2.產生patch
git format-patch -1
會產生0001xxxxx.patch檔案在當前目錄

repo status error 
prior sync failed;rebase still in process
在當前資料夾用以下解決方式
git rebase --abort
git am -3 --abort

**切換遠端branch到local branch
git fetch
git branch -r 查看要切換的remotes/xx/xx branch
git checkout -b "local branch" "remote branch"

Ref:

1.http://blog.longwin.com.tw/2009/05/git-learn-test-command-2009/

2.http://ncu-csie-snmg.github.io/2013-NCU-CSIE-Website-Design-Competition/git.html

3.http://abkabkabkyes.blogspot.tw/search/label/Git

4.詳細各項指令方式
http://homeserver.com.tw/2013/09/24/git-%E5%B8%B8%E7%94%A8%E6%8C%87%E4%BB%A4/

5.http://kit168.blogspot.tw/2013/03/git.html

沒有留言:

張貼留言