-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitutils.sh
94 lines (75 loc) · 1.93 KB
/
gitutils.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
93
# Utility functions for git
#
# Install like this:
# cd ~ && git clone https://gist.github.com/botverse/2d1458200db1b84d5620 .gitfonz
# echo "source .gitfonz/gitutils.sh" >> .bash_profile
# $ gc This is my comment
# => git commit -a -m "This is my comment"
function gc() {
#from http://stackoverflow.com/a/21453306/252675
#assuming flag is first arg and optional
flag=$1
[[ $1 = ${1#-} ]] && unset $flag || shift
concat=$(printf '%s ' ${@})
git commit -a -m "${concat% }" # to remove the trailing space
}
# $ gp
# => git push origin [CURRENT_BRANCH]
function gp() {
git push origin `git rev-parse --abbrev-ref HEAD`
}
# $ ga
# => git add .
function ga() {
git add .
}
# $ gac This is my comment
# => ga && gc This is my comment
function gac() {
ga
gc "$@"
}
# $ gb branch-name
# if branch exist
# => git checkout branch-name
# if branch doesnt exist will ask for confirm
# => git checkout -b branch-name
function gb () {
branch_name=$1
git show-ref --verify --quiet refs/heads/${branch_name}
if [ $? == 0 ]
then
git checkout ${branch_name}
return;
fi
read -p "Branch $branch_name does't exist, do you want to create it? " -n 1 -r
echo # blank line
if [[ $REPLY =~ ^[Yy]$ ]]
then
git checkout -b ${branch_name}
fi
}
# $ gs
# => git branch --sort=-committerdate
function gs () {
git branch --sort=-committerdate
}
# $ changedsince branch-name [...diffargs]
# => changes in branch-name since your current tree diverged
function changedsince() {
if [[ $# = 0 ]]; then
echo "Usage: changesince [target] [...diffargs]"
echo "Example: "
echo " changesince master -- src/config"
echo " will tell you what changed in src/config in master branch since"
echo " your current branch diverged"
exit 1
fi
target=$1
shift
current=$(git rev-parse --verify HEAD)
common=$(git merge-base $current $target)
command="git diff $common $target $@"
echo $command
eval $command
}