-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitaliases
100 lines (86 loc) · 2.38 KB
/
.gitaliases
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
94
95
96
97
98
99
function git_ls_ignored () {
(cd "$GIT_PREFIX" ; git status --ignored -s | grep '^!!' | cut -c 4-)
}
function git_ls_untracked () {
(cd "$GIT_PREFIX" ; git status "${1:-.}" -s | grep "^ *??" | cut -c 4-)
}
function git_pristine {
git reset $1 --hard && git clean -fX && git clean -fx && git clean -fd
}
function git_gc_all {
git -c gc.reflogExpire=0 \
-c gc.reflogExpireUnreachable=0 \
-c gc.rerereresolved=0 \
-c gc.rerereunresolved=0 \
-c gc.pruneExpire=now \
gc $@
}
function git_log_new () {
c=$(git status -sb .git | grep 'ahead' | sed 's/.*\[ahead \([0-9]*\)\]/\1/')
if [[ ! $c -eq "" ]]; then
git log -n$((c+1)) "$@"
else
echo Current branch up-to-date with remote
fi
}
function git_ref2hash () {
git log -1 --format=format:"%H" ${1}
}
function git_checkout_modified {
# git ls-files -m | xargs git checkout
(cd "$GIT_PREFIX" ; git_checkout_modified_currentdir "$@")
}
function git_checkout_modified_currentdir {
fs=$(git ls-files -m $1)
if [[ ! -z "$fs" ]]; then
printf \
"This overwrites the following modified files. There is no way to get them back!\n\
$fs\n\
Are you sure? [Y/y]"
read -p ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
git ls-files -m -z $1 | xargs -0 git checkout
fi
fi
}
function git_add_modified {
(cd "$GIT_PREFIX" ; git_add_modified_current_dir "$@")
}
function git_add_modified_current_dir {
git ls-files -m -z "${1:-.}" | xargs -0 git add
}
function git_add_to_commit {
if [ $# -eq 1 ]; then
oldcommit=$1
changes=$(git ls-files -m)
changes="${changes// }"
if ! [[ -z ${changes} ]]; then
git stash push --keep-index -m "tmp - rebase current work onto $oldcommit"
fi
git commit --fixup=${oldcommit}
editor=$(git config --get core.editor)
git config core.editor ":"
(
EDITOR=":"
GIT_EDITOR=":"
git rebase --interactive --autosquash ${oldcommit}^
)
if ! [[ -z ${changes} ]]; then
git stash pop
fi
git config core.editor "${editor// /\ }"
elif [ $# -eq 0 ]; then
git commit --amend --no-edit
else
echo Expected 0 or 1 arguments, got "$#":
echo "$@"
fi
}
function git_pull_ff {
mod_status=`git stash push`
git pull --ff-only
if [ "$mod_status" != "No local changes to save" ]; then git stash pop; fi;
}
function git_status_nosm {
(cd "$GIT_PREFIX" ; git status --ignore-submodules=all "$@")
}