-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit
More file actions
229 lines (193 loc) · 5.32 KB
/
Copy pathgit
File metadata and controls
229 lines (193 loc) · 5.32 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env zsh
#
runname=`basename $0`
case $runname in
dcm)
repository=(github1 github2 github3 github4 github5) # remote repository name
branch=(stable master develop) # branch name
bakrepo=(bak) # backup repository name
;;
kg)
repository=(github)
branch=(main master develop) # branch name
bakrepo=(bak) # backup repository name
;;
safer)
repository=(github)
branch=(master develop) # branch name
bakrepo=(bak) # backup repository name
;;
ob)
repository=(obnotes)
branch=(master)
bakrepo=(bak)
;;
*)
repository=(origin)
branch=(master)
bakrepo=(bak)
;;
esac
fgit () {
if [[ "x$1" != "x" ]]; then
run=$1; shift
else
run=pull
fi
if [[ "x$1" != "x" ]]; then
repo=($1); shift
else
repo=($repository[@])
fi
if [[ "x$1" != "x" ]]; then
bran=($1); shift
else
bran=($branch[@])
fi
if [[ "x$1" != "x" ]]; then
force="--$1"; shift
else
force=
fi
echo
echo "* Git $run --- "
echo " repo = ${repo[@]}: ${#repo[*]}"
echo " bran = ${bran[@]}: ${#bran[*]}"
mission=0
total=$[ ${#repo[@]} * ${#bran[@]} ]
for re in ${repo[@]}; do
for br in ${bran[@]}; do
let mission++
echo
echo "----------------------------------------------------"
echo " [$mission/$total]: "
echo " $run repository: $re/$br ... "
echo " **** *************** "
echo
git $run $re $br $force --tags
done
done
echo "----------------------------------------------------"
}
fpush () {
if [[ "x$1" != "x" ]]; then
fr=$1; shift
else
fr=
fi
for re in ${repository[@]}; do
for br in ${branch[@]}; do
fgit push $re $br $fr
done
done
}
fpull () {
for re in ${repository[@]}; do
fgit pull $re
done
}
ffetch () {
for re in ${repository[@]}; do
fgit fetch $re
done
}
fbak () {
if [[ $1 == "" ]]; then
run=push
else
run=$1; shift
fi
for re in ${bakrepo[@]}; do
fgit $run $re
done
}
gck () {
if [[ `git branch --list $1` ]]; then
git switch $1
else
git switch -c $1
fi
}
alias gits='git status'
alias gstb='gck stable'
alias gmas='gck master'
alias gmain='gck main'
alias gdev='gck dev'
alias gf1='gck f1'
alias gdf1='git branch -D f1'
alias glb='git branch -vv'
alias grb='git branch -r -vv'
alias gd='git branch -D'
alias gdr='git push -d '
alias glog='git log --color --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit'
alias gmm='git merge main'
alias gmf='git merge f1'
gcom () {
git add .
git commit -a -m "$1"
}
gtmp () {
gcom "update on `date` "
}
gpush () {
git push github --follow-tags
}
fatpush () {
echo "push fat$1 ..."
git push fat$1 develop --force --follow-tags
}
gpull () {
git pull github develop
}
gfat () {
git push fat$1
}
# list top 10 files (most large size)
gl10 () {
git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10
}
glarge () {
git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -$1
}
# delete files thoroughly!!!
grmt () {
echo "delete file/directory thoroughly, so be carefully doing it!!!"
echo -n " * please input yes/no: "
read continue
if [[ $continue == "yes" ]]; then
git filter-branch --force --index-filter "git rm -rf --cached --ignore-unmatch $1" --prune-empty --tag-name-filter cat -- --all
# 删除original文件夹
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
rm -rf .git/refs/original/
# 修剪旧的reflog条目
git reflog expire --expire=now --all
# 验证数据库中对象的连接性和有效性
git fsck --full --unreachable
# 打包解压缩的对象。 删除冗余的对象
git repack -A -d
# 清理不必要的文件并优化本地存储库
git gc --aggressive --prune=now
fi
}
alias gclean='git gc --aggressive --prune=now'
alias gabandon='git checkout . && git clean -xdf'
#-
case $runname in
ob)
alias cdob='cd /Users/fengh/Documents/RDS/NOTES/Obsidian'
alias obsync='rsync -alvzrtopg --progress --delete /Users/fengh/Library/Mobile\ Documents/iCloud~md~obsidian/Documents/RDS . && git add . && git commit -a -m "sync on `date`"'
alias gbakob='fgit push'
alias obwork='cdob && obsync; gbakob'
;;
dcm)
alias dcmclone='git clone /Users/fengh/Research/DCM'
alias fpull3='fgit pull github3 develop'
;;
safer)
source ~/Init/dcmenv
alias slave='/Users/fengh/Research/FORECAST/DCM/SAFER/src/slave/slave.py'
alias master='/Users/fengh/Research/FORECAST/DCM/SAFER/src/master/master.py'
;;
*)
;;
esac