Git 构建分布式版本控制系统
一.版本控制概念
记录开发文件的时间机器,更好的开发,挽回代码错误带来的损失
分类
本地版本控制系统
集中化的版本控制系统CVS、Subversion(SVN)
分布式版本控制系统GIT
二.产品
github
公共的服务器
GitHub注册
https://guides.github.com/activities/hello-world/
我注册好了,直接登录
三.Gitlab部署
官网链接:https://about.gitlab.com/downloads/#centos7
Install and configure the necessary dependencies
准备一台全新的虚拟机,4G以上的内存,关闭防火墙和selinux
将提前官网下载的包拷贝到服务器上,并解压
[root@192 ~]# rz
[root@192 ~]# ls
6.Git-software.zip anaconda-ks.cfg
[root@192 ~]# unzip 6.Git-software.zip
Archive: 6.Git-software.zip
inflating: gitlab-ce-9.1.0-ce.0.el7.x86_64.rpm
inflating: github2.pdf
安装依赖的环境
[root@192 ~]# sudo yum install curl policycoreutils openssh-server openssh-clients
[root@192 ~]# sudo systemctl start sshd
[root@192 ~]# sudo systemctl enable sshd
#安装邮件服务
[root@192 ~]# sudo yum install postfix
[root@192 ~]# sudo systemctl start postfix
[root@192 ~]# sudo systemctl enable postfix
Add the GitLab package server and install the package
由于国外的网站下载和安装太慢,一般不用官网安装,用rpm安装
rpm安装
安装刚才解压的包
[root@192 ~]# yum -y install gitlab-ce-9.1.0-ce.0.el7.x86_64.rpm
官网安装
#添加官网的yum仓库
[root@192 ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[root@192 ~]# sudo yum install gitlab-ce
Configure and start GitLab
提示,安装的时间会很长,请耐心等待!
#自动配置文件权限,安装数据库….
[root@192 ~]# sudo gitlab-ctl reconfigure
···过程略
Running handlers:
Running handlers complete
Chef Client finished, 324/433 resources updated in 57 seconds
gitlab Reconfigured!
Browse to the hostname and login
访问页面
192.168.200.140,gitlab占用80端口
创建密码
创建八位新的密码,然后用root登录即可
欢迎页面
创建项目
推送ssh秘钥
1.秘钥提示
记住并粘贴下图中的这个地址,用于下载项目(文档容器)
http://root@192.168.200.140/root/project2.git
2.生成密钥
[root@192 ~]# ssh-keygen
[root@192 ~]# ls .ssh/
id_rsa id_rsa.pub
3.上传秘钥
查看秘钥
[root@192 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+UukPfHJaL9Rnpre0f+yGKmwab91rJgwxbQDnIUVGYj5GEnBKwCoHtVBVjSbFIKcmR95kOVQa5pUUCsqDc6k50mB3NU2t4PsnI0aceIMS5HRXMPGSkW8pVPlPy8U9Uw2WQ9Z8V8R9wzyrpEusw/cWKlF1gaXEN5rR9On5dNEaclDzHz914TkwP/sAZlZNXkwxhDuZOOkJXOb0GubLUni8inpa3EuUUTVm99RDDVJ2UEWYSTTsOkp7WZct6VwLoR2qRW1S6V2dnaRuc6WCdIf1ZQQsgt9b6sD1mAopaBPR2eOP7qkfrUgbJarnYRjWvWav9uZlkHECs9mmWUdz+AG/ root@192.168.200.140
4.查看秘钥
5.链接地址
用于命令行,或客户端程序进行下载使用
使用gitlab
图形界面测试
创建文件
上传文件
下载文件
命令行测试
上面复制的域名:
http的:http://root@192.168.200.140/root/project2.git
ssh的:git@192.168.200.140:root/project2.git
1.克隆服务器的文件
[root@192 ~]# yum -y install git
#使用的用户名是域名的显示用户名
[root@192 ~]# git config --global user.name "root"
[root@192 ~]# git config --global user.email "root@localhost"
#注意您粘贴的地址中,使用了什么用户名。
[root@192 ~]# git clone git@localhost:root/project2.git
正克隆到 'project2'...
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:W6Jwu++IwI0SqmWqjhGpDIetIJu3S6VnKoRBXNqS0Fk.
ECDSA key fingerprint is MD5:18:bc:5c:7c:8d:20:e6:c2:f2:fa:dd:7d:b6:58:00:bf.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
接收对象中: 100% (9/9), 337.41 KiB | 0 bytes/s, done.
[root@192 ~]# ls
project2
[root@192 ~]# cd project2/
#刚才上传的文件
[root@192 project2]# ls
1.jpg 1.php 3.jpg.jfif
2.上传文件
#进入工作目录
[root@192 ~]# cd project2/
[root@192 project2]# pwd
/root/project2
#写个测试文件,写什么不重要
[root@192 project2]# echo 1234567 > 3333.sh
#初始化
[root@192 project2]# git init
重新初始化现存的 Git 版本库于 /root/project2/.git/
#配置远程服务器地址
[root@192 project2]# git remote add origin git@192.168.200.140:root/project2
fatal: 远程 origin 已经存在。
#建立当前文件夹下所有的文件,为准备上传的文件
[root@192 project2]# git add .
#提交上传说明
[root@192 project2]# git commit -m 'xushengkai2022'
[master 68102a1] xushengkai2022
1 file changed, 1 insertion(+)
create mode 100644 3333.sh
#上传
[root@192 project2]# git push -u origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 265 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@localhost:root/project2.git
8b95ce8..68102a1 master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
如果远程服务器配置报错,因为之前已经配置过其他远程服务器。可以用命令清除掉
git remote rm origin + ssh地址
在页面查看上传结果