git bare 项目

警告
本文最后更新于 2023-05-19,文中内容可能已过时。

正确做法

colo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cd ~
mkdir tbt2snap.recover
cd tbt2snap.recover
git init --bare ./tbt2snap.recover.git

## bare 仓库不保存具体内容,需要我们通过设置 post-receive 来同步远程仓库内容
## 通过这个控制从 master pull 到哪个目录
./tbt2snap.recover.git
cd hooks
touch post-receive
chmod +x post-receive
vim post-receive

#/bin/bash
GIT_WORK_TREE=/home/ops/tbt2snap.recover git checkout -f master
 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
tree -L 2
.
├── clear.sh
├── README.md
├── release.sh
├── tbt2snap.recover.git
│   ├── branches
│   ├── config
│   ├── description
│   ├── HEAD
│   ├── hooks
│   ├── index
│   ├── info
│   ├── logs
│   ├── objects
│   └── refs
└── template
    ├── colo.conf
    ├── hub.conf
    ├── hub.csv
    ├── run.hub.sh
    ├── run.t2s2.sh
    ├── run.term.sh
    ├── t2s2.conf
    └── terms.csv

8 directories, 15 files

local

1
2
3
4
## git 作为下一层仓库,通过 post-receive 控制同步内容
git remote add colo116 ssh://ops@192.168.1.177:61116/home/ops/tbt2snap.recover/tbt2snap.recover.git

git push colo116

remote

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
mkdir tools.git
cd tools.git
ls -alh
git init --bare

cd hooks
touch post-receive
chmod +x post-receive
vim post-receive

#/bin/bash
GIT_WORK_TREE=./ git checkout -f master

#while read oldrev newrev ref
#do
#    branch=´echo $ref | cut -d/ -f3´
#    GIT_WORK_TREE=../ git checkout -f $branch
#done

local

1
2
3
4
5
6
7
8
9
git clone git@192.168.1.171:lfang/tools.git

cd tools
vim readme.md
git add readme.md
git commit -m 'add readme'

git remote add colo110 ssh://192.168.1.177:61110/home/ops/tmp/tools.git
git push ssh://ops@192.168.1.177:61110/home/ops/tmp/tools.git

remote

这样,我们在 remote 机器即可看到变动

1
2
3
4
5
6
7
git log

commit 7bf73f38fad70da7116842ee73dc4f02cc44c932
Author: “williamlfang” <“william.lian.fang@gmail.com”>
Date:   Fri May 19 15:25:34 2023 +0800

    add readme

相关内容

william 支付宝支付宝
william 微信微信
0%