Git 常用指令

git --version : 查看 Git 版本。
git clone <儲存網址> : 複製儲存內容。
git config --list : 列出 config 的內容。
git config --list --show-origin : 列出所有 config 的檔案及內容。
git config --global user.name "John Doe" : 設定使用者名稱為"John Doe"。
git config user.name : 查看 config 中 user.name 的值。
git config --global user.email johndoe@example.com : 設定使用者 email 為 johndoe@example.com。
git config --global core.editor emacs : 設定要使用的文字編輯器為 emacs。
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" : 設定 Notepad++ 為要使用的文字編輯器。
git config --show-origin rerere.autoUpdate : 查看 config 中 rerere.autoUpdate 的值是來自哪一個檔案。
git help <verb> : 列出 <verb> 的說明網頁
git help config : 列出 config 的說明網頁
git init : 啟動所在資料夾的 git 管控功能
git add <file>... : 將檔案加入 git 管控
git checkout -- <file>...撤銷檔案的變更
git commit -m '註解內容' : 將變更簽入並加上註解
git commit --amend : 修正變更簽入內容
git clone 網址 : 下載一個既存的 git repository
git <verb> --help : 列出 <verb> 的說明網頁
git help config : 列出 config 的說明網頁
git add -h : 列出 add 的簡要說明
git add *.c:加入現有的 c 程式檔
git add LICENSE:加入 LICENSE 這個檔案
git clone https://github.com/tester/projectname :從 github 複製一個專案
git clone https://github.com/tester/projectname dirname :從 github 複製一個專案到指定的目錄
git status : 查看目前 git 狀態
git status -s : 查看目前 git 狀態,只顯示簡單訊息
git reset HEAD <file>...unstage 檔案
git diff列出有異動的部份
git diff --staged列出目前 stage 與上次 commit 的狀態異動
git diff --cached列出目前已經放入 stage 的狀態
git difftool用來工具程式顯示異動內容
git difftool --tool-help顯示目前系統中有那些 difftool可用
git rm <file> : 移除 <file>
git rm --cached <file>撤回某個已經 commit 的檔案
git rm log/\*.log移除 log 目錄下所有的 log 檔
git rm \*~移除所有檔名以~結尾的檔案
git mv <file_from> <file_to>將 <file_from> 的內容遷移到 <file_to>
git reset HEAD <file>..."將檔案恢復成 unstage 狀態
git log顯示變更紀錄
git log -p顯示變更詳細紀錄
git log --patch顯示變更詳細紀錄
git log -2只顯示最後2筆變更紀錄
git log --stat顯示變更紀錄統計資料
git log --oneline將每次的變更紀錄顯示成一行
git log --pretty格式化顯示變更紀錄資料
git log --pretty=short將變更紀錄以最簡短的方式顯示
git log --pretty=full將變更紀錄以簡短的方式顯示
git log --pretty=fuller將變更紀錄以稍完整的簡短方式顯示
git log --pretty=format:"%h - %an, %ar : %s"將變更紀錄以 hash - Author name, relative date : Subject 的格式顯示
git log --pretty=format:"%h %s" --graph將變更紀錄以 hash Subject 的格式用 ASCII 顯示
git log --since=2.weeks顯示兩週以來的變更
git log -S function_name只顯示有變更 function_name 內容的紀錄
man gitignore : 列出 <gitignore> 的說明網頁
man git-<verb> : 列出 <verb> 的說明網頁

Useful options for git log --pretty=format

OptionDescription of Output
%HCommit hash
%hAbbreviated commit hash
%TTree hash
%tAbbreviated tree hash
%PParent hashes
%pAbbreviated parent hashes
%anAuthor name
%aeAuthor email
%adAuthor date (format respects the --date=option)
%arAuthor date, relative
%cnCommitter name
%ceCommitter email
%cdCommitter date
%crCommitter date, relative
%sSubject
    		
	
	
	
	

Git 設定檔

	/etc/gitconfig file : 系統層級設定檔。使用 --system 參數來設定。通常放在 Git 的安裝目錄中。 
	~/.gitconfig or ~/.config/git/config file : user 層級設定檔。使用 --global 參數來設定。通常是放在 Disc:\Users\$USER 目錄中。
    .git/config : 專案層級設定檔。