Category Archives: DevTools

Git bash alias config

SourceTree是一个功能很强大的Git GUI工具,但是就是太慢,且在Windows下会出现莫名占用一个核心CPU。于是开始折腾Git bash,目前基本够用。其中alias部分的配置文件如下,供参考,放到 /username/.gitconfig里面即可。

l = log --pretty=format:"%C(yellow)%h\ %ad%Cred%d\ %Creset%s%Cblue\ [%cn]" --decorate --date=short
a = add
ap = add -p
c = commit --verbose
ca = commit -a --verbose
cm = commit -m
cam = commit -a -m
m = commit --amend --verbose
d = diff
ds = diff --stat
dc = diff --cached
s = status
ss = status -s
co = checkout
cob = checkout -b
# list branches sorted by last modified
b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
# list aliases
la = "!git config -l | grep alias | cut -c 7-"

其中我最喜欢的是git lg,附图2张,右键查看大图(一个“MD程序员”上镜)。
git lg
git lg2

Git cheat sheet

  • Replace crlf

git config core.autocrlf true


  • Remote branch delete

git push origin --delete <branchName>


  • Apply new gitignore

To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"

To undo git rm –cached filename, use git add filename


  • Undo all uncommitted changes

git checkout .


  • file log

Git log -1 --

  • fix error Cant't ref..

$ git gc --prune=now

$ git remote prune origin


  • 恢复误删除文件, notepad++ 把换行\r\n换成;一次执行多个文件
  1. Use git log –diff-filter=D –summary to get all the commits which have deleted files and the files deleted;
  2. Use git checkout $commit~1 filename to restore the deleted file.


  • Prevent gc

git config --global 0


  • View file log

Gitk <filename>


  • Getting existing git branches to track remote branches

git branch --track origin/branch_name


  • rollback git repo to specific commit

git reset --hard <tag/branch/commit id>
git checkout HEAD -- my-file.txt

  • Log search

git log --grep="Build 0051"


  • reverting specific commits from git
    $ git revert --no-commit b49eb8e 1d8b062
    Files that were modified in those 2 commits will be changed in your working directory
    If any of those 2 commits had changed ‘a’ then you could discard the revert for it:
    $ git checkout a
    $ git commit -a -m "Revert commits b49eb8e and 1d8b062"


Config proxy for Nuget

  1. Download Nuget.
  2. Open command line, in folder of Nuget.exe, press Alt+Shif+F, select open command window here

Commands to set nuget proxy

nuget.exe config -set http_proxy=http://my.proxy.address:port
nuget.exe config -set http_proxy.user=mydomain\myUserName
nuget.exe config -set http_proxy.password=mySuperSecretPassword

Commands to view nuget proxy

nuget.exe config http_proxy
nuget.exe config http_proxy.user
nuget.exe config http_proxy.password