顯示廣告
隱藏 ✕
看板 tails
作者 tails (QQ)
標題 [教學] Git使用教學 Part 4 -- 補充資料
時間 2012年03月12日 Mon. AM 02:53:09


本篇將不定時更新

Git名詞解釋:

repository  =  倉庫、程式庫等,總之言之就是庫,裡面記錄了所有變動的過程。可供追縱或回朔的參考
branch  =  分支,branch的概念可以參考此篇
commit  =  提交,每一次的commit都是個節點,正是追縱或回朔的參考點
remote  =  遠端,


Git常用指令一覽:

init系列:
git init  #建立一個目錄叫.git,裡面存放就是repository的所有記錄
git --bare init  #原本放在.git的目錄裡的資料改放在目前工作目錄,通常當remote端用

git clone <repository>  #將<repository>最新版整包拿下來並建立新目錄放進去

git status  #查看目前狀態,會顯示目前branch和列出與repository比對不合的files狀態

log系列:
git log  #查看目前branch所有變動記錄
git log --all  #查看所有變動記錄,含其他branch
git log --stat  #詳細的資訊
git log -p  #將所有log和修改過的檔案內容列出
git log -p <filename>  #顯示該檔案的所有變更內容差異列出
git log --pretty=oneline  #會顯示所有log的第一行hash與註解,在查commit的hash時很方便
git log <filename>  #檔案的所有log
git log <directory>  #目錄的所有log

show系列:
git show <tag>  #查此tag的commit修改內容
git show <tag>:<filename>  #查此tag的某一檔案修改內容
git show HEAD  #目前版本修改的資料
git show HEAD^  #前一版本修改的資料
git show HEAD^^  #前前一版本修改的資料
git show HEAD~4  #前前前前一版本修改的資料

add, rm, mv系列:
git add <filename>  #基本加入檔案
git add -u  #只加修改過的檔案, 新增的檔案不加入.
git add -i  #進入互動模式
git add .  #將資料先暫存到 staging area, add 之後再新增的資料, 於此次 commit 不會含在裡面.
git rm <filename>  #Git刪除
git mv <filename> <newfilename>  #Git改名

commit系列:
git commit  #基本提交
git commit -m <msg>  #加入訊息
git commit -a -m <msg>  #將所有修改過得檔案都 commit, 但是 新增的檔案 還是得要先 add.
git commit -a -v  #可以看到檔案哪些內容有被更改, -a 把所有修改的檔案都 commit

branch系列:
git branch  #列出目前有多少branch
git branch <newBranch>  #由目前所在的branch/master直接複製一份
git branch <newBranch> <branch>  #由<branch>產生新的branch
git branch <newBranch> <tag>  #由<tag>產生新的branch
git branch -d <branch>  #刪除<branch>
git branch -D <branch>  #強制刪除<branch>
git branch -r  #列出所有 remote repository branch
git branch -a  #列出所有 branch

checkout系列:
git checkout <branch>  #切換到<branch>
git checkout -b <newBranch>  #由現在的環境為基礎, 建立新的branch
git checkout -b <newBranch> <branch>  #由<branch>產生新的branch,並同時切換過去

tag系列:
git tag  #列出所有tag
git tag <tag> <hash>  #為<hash>的commit建立tag
git tag -d <tag>  #將<tag>刪掉

remote系列:
git remote
git remote add <remote> <repository>  #增加遠端repository的branch
git remote show  #秀出現在有多少遠端repository
git remote rm <remote>  #刪掉<remote>
git remote update  #更新所有repository branch

fetch, pull系列:
git fetch <remote>  #抓取<remote>所有branch最新的檔案
git pull <remote> <branch>  #把<remote>的<branch>下載回來並做merge

reset系列:
git reset --hard HEAD  #還原到最前面
git reset --hard HEAD~3
git reset --soft HEAD~3
git reset HEAD filename  #從stage狀態回到unstaging或untracked

--
參考資料
官方Manual Page
Git初學筆記 - 指令操作教學

--
※ 作者: tails 時間: 2012-03-12 02:53:09
※ 編輯: tails 時間: 2012-03-13 00:35:43
※ 看板: tails 文章推薦值: 3 目前人氣: 0 累積人氣: 4920 
分享網址: 複製 已複製
( ̄︶ ̄)b Knuckles, d2wu550, pig 說讚!
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇