git pull

push

1
2
3
4
5
git clone https://gitee.com/tookoff/x-spring-boot.git

❯ git add .
❯ git commit -m "提交"
❯ git push origin master:develop

git push :

其中 <remote_name> 表示远程仓库名称(通常为 origin);<local_branch> 表示本地分支名称;<remote_branch> 表示远程分支名称。如果不指定 <remote_branch>,则会在远程仓库创建与本地分支同名的新分支。

pre-receive hook declined

push前置检查

脚本错误/权限不足/返回非零状态码/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
!/bin/bash
read oldrev newrev refname

if [[ "$refname" == "refs/heads/master" ]]
then
# 获取最后一次提交的提交信息
message=$(git log --format=%B -n 1 $newrev)
# 提取出bug号
bug=$(echo "$message" | grep "bug" | awk '{print $2}')
# 检查bug是否存在
if [[ -z $bug ]]
then
echo "提交信息必须包含bug号"
exit 1
fi
fi

exit 0

pull

稀疏检出sparse checkout

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
#!/bin/bash

print_help() {
cat <<EOF
use params
-h , --help 说明 不支持分支
-u , --url *必须,下载文件的链接(如https:://github.io/xx/tree/master/a/b ,下载b)


EOF
}

function src(){
if [[ "$1" =~ "github.com" ]] || [[ "$1" =~ "gitee.com" ]];then
echo "downloadUrl--> $1"
else
echo "不支持"
exit 1
fi
}

while [ $# -ge 0 ]; do
case $1 in
-h|--help)
print_help
exit 1
;;
-u|--url)
src $2
break
;;
* )
echo "use param -h or --help !"
exit 1
;;
esac
done
function type(){
uri=$(echo $1 | grep "/tree/master/" | grep -v grep)
echo "---$uri"
if [[ $uri != "" ]];then
echo "-------/tree/master"
uri=${url%/tree/master*}".git"
down=${url#*/tree/master/}
else
echo "-------/blob/master"
uri=$(echo $1 |grep -v grep | grep "/blob/master/")
if [[ $uri != "" ]];then
uri=${url%/blob/master*}".git"
down=${url#*/blob/master/}
else
echo "只支持拉取master文件下载"
exit 1
fi
fi
}

url=$2

file=${url##*/}

uri=
down=
type $2


if [ ! -f "$file" ];then
mkdir $file
fi
cd $file

git init
echo "==================添加 源==================="
git remote add -f origin $uri
#稀疏检出
git config core.sparsecheckout true
#拉取文件
echo "$down">>.git/info/sparse-checkout
echo "==================开始拉取==================="
git pull origin master

rm -rf .git
mv $file/* . && rm -r $file


echo "==================$PWD==================="

利用git稀疏检出拉取部分文件

js实现下载

kinolien gitzip

点击打赏
文章目录
  1. 1. push
    1. 1.1. pre-receive hook declined
  2. 2. pull
  3. 3. js实现下载
载入天数...载入时分秒... ,