Tag Archives: git

Git bash alias config

Published / by youenzeng / Leave a Comment

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

[alias]
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张,右键查看大图。
git lg
git lg2

Git cheat sheet

Published / by youenzeng / Leave a Comment
  • Replace crlf

git config core.autocrlf true

source

  • Remote branch delete

git push origin --delete <branchName>

source

  • 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

source

  • Undo all uncommitted changes

git checkout .

source

  • file log

Git log -1 -- file.name

  • fix error Cant't ref..

$ git gc --prune=now

$ git remote prune origin

source

  • 恢复误删除文件, 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.

source

  • Prevent gc

git config --global gc.auto 0

source

  • View file log

Gitk <filename>

source

  • Getting existing git branches to track remote branches

git branch --track origin/branch_name

[source](http://stackoverflow.com/questions/1184518/getting-existing-git-branches-to-track-remote-branches>

  • rollback git repo to specific commit

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

  • Log search

git log --grep="Build 0051"

source

  • 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"

source