Skip to content

Instantly share code, notes, and snippets.

@ohshita
Last active June 7, 2024 06:30
Show Gist options
  • Save ohshita/580f0c6cf3142368dedb5bc429afd8bb to your computer and use it in GitHub Desktop.
Save ohshita/580f0c6cf3142368dedb5bc429afd8bb to your computer and use it in GitHub Desktop.
[color]
status = auto
diff = auto
branch = auto
interactive = auto
grep = auto
log = auto
[push]
default = upstream
[pull]
rebase = true
[merge]
ff = false
[filter "media"]
clean = git-media-clean %f
smudge = git-media-smudge %f
[alias]
## log
ranking = shortlog -s -n --no-merges
contribute-ranking = "!f () { git ls-files --cached | grep -E $1 | xargs -I{} git blame -e -wc {} | LANG=C sed -e 's/^[^<]*<//g' -e 's/>.*$//g' | sort | uniq -c | sort -nr;}; f"
authorlog = "!f () { git log --no-merges --author=$1 --date=short --pretty=format:\"%Cgreen%h %Cblue%cd %Cred%cn%x09%Creset%s\" ;}; f"
branch-graph = log --graph --date-order -C -M --pretty=format:'<%h> %ad [%an] %Cgreen%d%Creset %s' --all --date=short
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
lga = log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
## branch
br = branch -vv
no-merged-branch = branch -vv --no-merged
merged-branch = branch -vv --merged
clean-merged-branch = !git branch --merged | grep -v \\* | xargs -I % git branch -d %
## reset & clean
hard-reset = reset --hard
reset-clean = !git reset --hard HEAD && git clean -f -d
## pull
# pull-all = "!f () { git fetch origin; for branch in `git branch -r | grep origin | grep -v HEAD | awk -F'/' '{print $2}'`; do git checkout $branch; done;}; f"
## work
difff = diff --word-diff
cherry-color = "!f () { git cherry -v "$@" | awk '{ if ($1 == \"+\") { color = \"green\" } if ($1 == \"-\") { color = \"red\" } cmd = \"git show --date=short --no-notes --pretty=format:\\047%C\" color $1 \" %h %Cgreen%cd %Cblue%cn %x09%Creset%s\\047 --summary \" $2; cmd | getline t; close(cmd); print t }' ;}; f"
cherry-ticket-numbers = "!f() { git cherry -v "$@" | cut -b 44- | awk 'match($0, /#[0-9]+/) { print substr($0, RSTART, RLENGTH) }' | sort -u ;}; f"
## uumerge
add-unmerged = "!f () { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
delete-unmerged = "!f () { git ls-files --deleted | cut -f2 | sort -u ; }; git rm `f`"
edit-unmerged = "!f () { git ls-files --unmerged | cut -f2 | sort -u ; }; vim `f`"
## alias
alias = "!f () { git config --get-regexp alias | cut -d'.' -f2 | if [ -z $1 ]; then cut -d' ' -f1 | sort | column; else grep $1' '; fi }; f"
## checkout
co = "!f () { git branch -a -vv --no-color | peco | sed 's/^[ *]*\\([^ ]*\\).*$/\\1/'; }; g () { if [ -z $1 ]; then git checkout `f`; else git checkout $*; fi }; g"
## status
st = status
## blame
pr = "!f() { git log --merges --oneline --reverse --ancestry-path $1...develop | fgrep 'Merge pull request #' | head -n 1; }; f"
pr-number = "!f() { git log --merges --oneline --reverse --ancestry-path $1...develop | fgrep 'Merge pull request #' | head -n 1 | grep -o '#[0-9]*'; }; f"
blame-pr = "!f () { git blame --first-parent $* | ruby -e 'b={}; STDIN.each { |l| c,s=l.chomp.split(/\\s+/,2); b[c]||= (pr=%x(git pr-number #{c}).chomp; sprintf(%(%-9s),pr==%()?c:%(PR #{pr}))); puts %(#{b[c]} #{s}) }'; }; f"
## grep
grep-all = "!f () { git grep $1 $(git show-ref | cut -d' ' -f2 | grep '/origin/') -- ${@:2}; }; f"
@ohshita
Copy link
Author

ohshita commented Jul 27, 2021

git grep-all を追加

@ohshita
Copy link
Author

ohshita commented Jun 7, 2024

途中改行が混入していたので消した

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment