-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-functions.sh
92 lines (82 loc) · 2.32 KB
/
git-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function git-push-for-review() {
echo -en "Specify branch of compare from(develop):"
read ans
[[ $ans = "" ]] && from='develop' || from=$ans
current_branch=`git branch | egrep '\*' | tr -d "* "`
echo -en "Specify branch of compare to(${current_branch}):"
read ans
[[ $ans = "" ]] && to=$current_branch || to=$ans
echo "from = ${from}, to = ${to}"
from_branch="${from}_for_review_${to}"
git checkout $from
git checkout -b $from_branch
git push origin $from_branch
git checkout $to
git push origin $to
echo "git pushed from_branch as: ${from_branch}"
echo "git pushed to_branch as: ${to}"
echo "Let's create pull request on remote repository."
}
function git-delete-merged() {
merged=`git branch --merged | egrep -v '\*|develop|master'`
if [[ $merged = "" ]]; then
echo 'No merged branch.'
return 0
fi
echo -en "$merged\\ndelete? (y)es/(n)o: "
read ans
if [[ $ans =~ ^y(es)?$ ]]; then
echo "$merged" | xargs git branch -d
else
echo 'Cancelled.'
fi
}
function git-checkout-force() {
local branch=$1
if [ $branch = $(git rev-parse --abbrev-ref HEAD) ]; then
echo "Already on '$branch'" >&2
return 0
fi
git branch -D $branch > /dev/null 2>&1
git checkout -b $branch
}
function git-committer-change() {
git filter-branch --commit-filter '
GIT_AUTHOR_NAME="Izuta Hiroyuki"
GIT_AUTHOR_EMAIL="[email protected]"
GIT_COMMITTER_NAME="Izuta Hiroyuki"
GIT_COMMITTER_EMAIL="[email protected]"
git commit-tree "$@"
' HEAD
}
alias ga='git add'
alias gap='git add -p'
alias gb='git branch'
alias gcm='git commit -v'
alias gca='git commit --amend'
alias gcae='git commit --allow-empty'
alias gco='git checkout'
alias gcof='git-checkout-force'
alias gcp='git cherry-pick'
alias gd='git diff'
alias gdm='git-delete-merged'
alias gg='git grep'
alias gl="git log --pretty='%h %ci %s %cn'"
alias gpl='git pull'
alias grb='git rebase'
alias grbi='git rebase -i'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
for n in $(seq 10); do
alias grbi$n="git rebase -i HEAD~$n"
done
alias grs='git reset'
for n in $(seq 10); do
alias grs$n="git reset HEAD~$n"
done
alias gs='git status'
alias gsh='git show'
alias gskip='git update-index --skip-worktree'
alias gnoskip='git update-index --no-skip-worktree'
alias gps='git push'
alias gpsfr='git-push-for-review'