Git那些鮮爲人知的祕籍以及Sao操做

如須要了解其餘git操做:juejin.im/post/5d0c82…

Git配置

Git命令自定義別名

別名用來幫助你定義本身的git命令。好比你能夠定義 git a 來運行 git add --allhtml

要添加一個別名, 一種方法是打開 ~/.gitconfig 文件並添加以下內容:git

[alias]
  co = checkout
  cm = commit
  p = push
  # Show verbose output about tags, branches or remotes
  tags = tag -l
  branches = branch -a
  remotes = remote -v
複製代碼

...或者在命令行裏鍵入:github

$ git config --global alias.new_alias git_function
複製代碼

例如:bash

$ git config --global alias.cm commit
複製代碼

指向多個命令的別名能夠用引號來定義:app

$ git config --global alias.ac 'add -A . && commit'
複製代碼

下面列出了一些有用的別名:ide

別名 Alias 命令 Command 如何設置 What to Type
git cm git commit git config --global alias.cm commit
git co git checkout git config --global alias.co checkout
git ac git add . -Agit commit git config --global alias.ac '!git add -A && git commit'
git st git status -sb git config --global alias.st 'status -sb'
git tags git tag -l git config --global alias.tags 'tag -l'
git branches git branch -a git config --global alias.branches 'branch -a'
git remotes git remote -v git config --global alias.remotes 'remote -v'
git lg git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit -- git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit --"

自動更正

若是鍵入 git comit 你會看到以下輸出:post

$ git comit -m "Message"
# git: 'comit' is not a git command. See 'git --help'.

# Did you mean this?
# commit
複製代碼

爲了在鍵入 comit 調用 commit 命令,只需啓用自動糾錯功能:ui

$ git config --global help.autocorrect 1

複製代碼

如今你就會看到:this

$ git comit -m "Message"
# WARNING: You called a Git command named 'comit', which does not exist.
# Continuing under the assumption that you meant 'commit'
# in 0.1 seconds automatically...
複製代碼

帶顏色輸出

要在你的Git命令輸出里加上顏色的話,能夠用以下命令:spa

$ git config --global color.ui 1複製代碼

進一步瞭解 Git config 命令.

更直觀的Git Status

在命令行輸入以下命令:

$ git status
複製代碼

能夠看到:

加上 -sb 選項:

$ git status -sb
複製代碼

這回獲得:

Git資源

Title Link
Official Git Site git-scm.com/
Official Git Video Tutorials git-scm.com/videos
Code School Try Git try.github.com/
Introductory Reference & Tutorial for Git gitref.org/
Official Git Tutorial git-scm.com/docs/gittut…
Everyday Git git-scm.com/docs/everyd…
Git Immersion gitimmersion.com/
Ry's Git Tutorial rypress.com/tutorials/g…
Git for Designer hoth.entp.com/output/git_…
Git for Computer Scientists eagain.net/articles/gi…
Git Magic www-cs-students.stanford.edu/~blynn/gitm…

Git參考書籍

Title Link
Pragmatic Version Control Using Git www.pragprog.com/titles/tsgi…
Pro Git git-scm.com/book
Git Internals Peepcode peepcode.com/products/gi…
Git in the Trenches cbx33.github.com/gitt/
Version Control with Git www.amazon.com/Version-Con…
Pragmatic Guide to Git www.pragprog.com/titles/pg_g…
Git: Version Control for Everyone www.packtpub.com/git-version…

如你們還有什麼祕籍和Sao操做能夠留言給我

相關文章
相關標籤/搜索