1:Git branch 一般用於分支的操作,比如創建分支,查看分支等等
git branch: 不帶參數:列出本地已經存在的分支,並且在當前分支的前面用"*"標記 git branch -r:查看遠程版本庫分支列表 git branch -a:查看所有分支列表,包括本地和遠程 git branch dev:創建名爲dev的分支,創建分支時需要是最新的環境,創建分支但依然停留在當前分支 git branch -d dev:刪除dev分支,如果在分支中有一些未merge的提交,那麼會刪除分支失敗,此時可以使用 git branch -D dev:強制刪除dev分支, git branch -vv :可以查看本地分支對應的遠程分支 git branch -m oldName newName:給分支重命名
2:Git checkout 操作文件、操作分支
操作文件 git checkout filename: 放棄單個文件的修改 git checkout .: 放棄當前目錄下的修改 操作分支 git checkout master: 將分支切換到master git checkout -b master: 如果分支存在則只切換分支,若不存在則創建並切換到master分支,repo start是對git checkout -b這個命令的封裝,將所有倉庫的分支都切換到master,master是分支名
3:Git log 日誌查看
1:如果不帶任何參數,它會列出所有歷史記錄,最近的排在最上方,顯示提交對象的哈希值,作者、提交日期、和提交說明。如果記錄過多,則按Page Up、Page Down、↓、↑來控制顯示。按q退出歷史記錄列表
2:顯示參數 書寫格式【git log +下列表內容】
-p:按補丁顯示每個更新間的差異,比下一條- -stat命令信息更全 --stat:顯示每次更新的修改文件的統計信息,每個提交都列出了修改過的文件,以及其中添加和移除的行數,並在最後列出所有增減行數小計 --shortstat:只顯示--stat中最後的行數添加修改刪除統計 --name-only:盡在已修改的提交信息後顯示文件清單 --name-status:顯示新增、修改和刪除的文件清單 --abbrev-commit:僅顯示SHA-1的前幾個字符,而非所有的40個字符 --relative-date:使用較短的相對時間顯示(例如:"two weeks ago") --graph:顯示ASCII圖形表示的分支合併歷史 —pretty=:使用其他格式顯示歷史提交信息,可選項有:oneline,short,medium,full,fuller,email,raw以及format:<string>,默認爲medium,如: --pretty=oneline:一行顯示,只顯示哈希值和提交說明(--online本身也可以作爲單獨的屬性) --pretty=format:” ":控制顯示的記錄格式,如: %H 提交對象(commit)的完整哈希字串 %h 提交對象的簡短哈希字串 %T 樹對象(tree)的完整哈希字串 %t 樹對象的簡短哈希字串 %P 父對象(parent)的完整哈希字串 %p 父對象的簡短哈希字串 %an 作者(author)的名字 %ae 作者的電子郵件地址 %ad 作者修訂日期(可以用 -date= 選項定製格式) %ar 作者修訂日期,按多久以前的方式顯示 %cn 提交者(committer)的名字 作者和提交者的區別不知道是啥? 作者與提交者的關係:作者是程序的修改者,提交者是代碼提交人(自己的修改不提交是怎麼能讓別人拉下來再提交的?) 其實作者指的是實際作出修改的人,提交者指的是最後將此工作成果提交到倉庫的人。所以,當你爲某個項目發佈補丁,然後某個核心成員將你的補丁併入項目時,你就是作者,而那個核心成員就是提交者(soga) %ce 提交者的電子郵件地址 %cd 提交日期(可以用 -date= 選項定製格式) %cr 提交日期,按多久以前的方式顯示 %s 提交說明 帶顏色的--pretty=format:” ",這個另外寫出來分析 以這句爲例:%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an> 它的效果是: 先斷句:[%Cred%h][%Creset -][%C(yellow)%d ][%Cblue%s][%Cgreen(%cd)][%C(bold blue)<%an>] 然後就是很明顯能得到的規律了 一個顏色+一個內容 顏色以%C開頭,後邊接幾種顏色,還可以設置字體,如果要設置字體的話,要一塊加個括號 能設置的顏色值包括:reset(默認的灰色),normal, black, red, green, yellow, blue, magenta, cyan, white. 字體屬性則有bold, dim, ul, blink, reverse. 內容可以是佔位元字符,也可以是直接顯示的普通字符 --date= (relative|local|default|iso|rfc|short|raw):定製後邊如果出現%ad或%cd時的日期格式 有幾個默認選項 --date=relative:shows dates relative to the current time, e.g. "2 hours ago". --date=local:shows timestamps in user’s local timezone. --date=iso (or --date=iso8601):shows timestamps in ISO 8601 format. --date=rfc (or --date=rfc2822):shows timestamps in RFC 2822 format,often found in E-mail messages. --date=short:shows only date but not time, in YYYY-MM-DD format.這個挺好用 --date=raw:shows the date in the internal raw git format %s %z format. --date=default:shows timestamps in the original timezone (either committer’s or author’s). 也可以自定義格式(需要git版本2.6.0以上),比如--date=format:'%Y-%m-%d %H:%M:%S' 會格式化成:2016-01-13 11:32:13,其他的格式化佔位符如下: %a:Abbreviated weekday name %A:Full weekday name %b:Abbreviated month name %B:Full month name %c:Date and time representation appropriate for locale %d:Day of month as decimal number (01 – 31) %H: Hour in 24-hour format (00 – 23) %I:Hour in 12-hour format (01 – 12) %j:Day of year as decimal number (001 – 366) %m:Month as decimal number (01 – 12) %M:Minute as decimal number (00 – 59) %p:Current locale's A.M./P.M. indicator for 12-hour clock %S:Second as decimal number (00 – 59) %U:Week of year as decimal number, with Sunday as first day of week (00 – 53) %w:Weekday as decimal number (0 – 6; Sunday is 0) %W:Week of year as decimal number, with Monday as first day of week (00 – 53) %x:Date representation for current locale %X:Time representation for current locale %y:Year without century, as decimal number (00 – 99) %Y:Year with century, as decimal number %z, %Z:Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown %%:Percent sign