版本控制概念
-
记录开发文件的时间机器
- 更好的开发
- 挽回代码错误带来的损失
- 更好的开发
分类
-
本地版本控制系统
-
集中化的版本控制系统 CVS、Subversion(SVN)
-
分布式版本控制系统GIT
产品
github
-
公共的服务器
-
GitHub注册
-
官网
- https://github.com/
-
图示
-
流程
- 注册账号
- 新建项目
- 克隆项目
-
git
-
git客户端
-
前提
- 1、github.com 注册账户
- 2、在github上创建仓库
-
1.生成本地ssh key
-
ssh-keygen -t rsa -C ‘git@github.com:cfg1573’
-t rsa 表示加密类型是rsa加密
-c 注释
-
邮箱要与github上注册的相同
-
[root@abc ~]# ssh-keygen -t rsa -C 'git@github.com' Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:YU6tRpZ8rzqUG7qw2jaAUHSjZCwmMM2S4C2IPLR8xKc git@github.com The key's randomart image is: +---[RSA 2048]----+ |*B=.o | |%=O+ o . o | |=@.oo O o | |. +E * + . | |.. S. . | |. . .+ . | | .. o o. | | .oo. o. | | .oo..... | +----[SHA256]-----+
-
-
-
2.复制 公钥,在github 中添加ssh key
-
cat .ssh/id_rsa.pub
[root@abc ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZ99Cjo4YQXLQsRAYNPyN4/y7AR8Oih+jkgQA8tylZ3Obxgk+ZdIYij/JdFUqBT4W8OmvzBhhhnAKNNOPwVZdINhffA1nJzhjtuutn40Fvxfl775g0Hg5MFtSYD3De7gvlrBTHgmDxwVQcNqJ35F85Cbidq7EPO/bDH2FFV7MLlucQUoGb5/GgbGWzMHOqSZ0d78VeklQoE1xNlJZ0zreMnsnCoB6ZAv1awdxkl+WLmueMO4FILDwDpfoR48KevJm3NnkA8pOIum2504CWZ6EaLHz4b0A90oBU/UVQ/a4bVyxZvrZ5Z8xP+iIrgcfWVvDO1YSgnOxTWDHbaxtLj0oh git@github.com
-
在github找到账户设置
-
选择ssh key
-
-
-
-
-
3.测试本地客户端
- yum install git
-
4.进行认证(但不能远程连接)
-
ssh -T git@github.com
]# ssh -T git@github.com The authenticity of host 'github.com (20.205.243.166)' can't be established. ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM. ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts. Hi cfg1573! You've successfully authenticated, but GitHub does not provide shell access.
-
-
5.在本地添加远程仓库用户名
- git config --global user.name ‘chenfuguo’
-
6.在本地添加远程仓库邮箱
- git config --global user.email ‘3543442463@qq.com’
-
7.启用默认的颜色设置
- git config --global color.ui true
- 不喜欢花花绿绿的就关了。git config --global color.ui false
- git config --global color.ui true
-
8.查看配置
- git config --list
- ls .gitconfig
- cat .gitconfig
-
9.上传远程仓库
-
mkdir test0731
-
cd test0731/
-
[root@web test0731]# git init
-
-
10.设置远程仓库地址
- 查看远程仓库地址
-
-
-
-
- git remote add origin git@github.com:cfg1573/test0731.git
-
- echo 111111 > 1.sh
- git add .
- [root@web test0731]# git commit -m ‘git本地第一次提交1.sh’
- # git push -u origin master
-
-
11.克隆远程仓库信息
- git clone git@github.com:cfg1573/test0731.git
- ls
- cd test0731/
- ls
-
git
-
纯命令行的软件
-
服务器&客户端
-
1.准备工作目录
- useradd git
- mkdir /git-root/
- 任意目录
- cd /git-root/
-
2.创建一个分支
- git init --bare shell.git
- 初始化空的 Git 版本库于 /git-root/shell.git/
- [root@abc git-root]# ls
- shell.git
- git init --bare shell.git
-
3.目录授权
- chown -R git:git shell.git/
-
4.切换git
- su - git
-
5.生成秘钥
-
ssh-keygen -t rsa
ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/var/opt/gitlab/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/opt/gitlab/.ssh/id_rsa. Your public key has been saved in /var/opt/gitlab/.ssh/id_rsa.pub. The key fingerprint is: SHA256:ZoWt/DTfxpq1Q6iGB1jdG0VsBzPNChRQJOHTVrylD6M git@abc The key's randomart image is: +---[RSA 2048]----+ | +*==*+ | | + o..=o=| | ..=.o+ * | | ..o.oo * | | oS o = + | | .o.o oEo. .| | o....= | | . + =.. | | o o .. | +----[SHA256]-----+
-
cd .ssh/
-
cp id_rsa.pub authorized_keys
-
logout
-
-
6.设置git账号的shell
- [root@abc git-root]# usermod -s /usr/bin/git-shell git
-
7.测试下载仓库
-
cd /opt/
-
git clone git@10.18.47.23:/git-root/shell.git
[root@abc opt]# git clone git@10.18.47.23:/git-root/shell.git 正克隆到 'shell'... git@10.18.47.23's password: warning: 您似乎克隆了一个空版本库。 [root@abc opt]# ls gitlab shell
-
-
8.测试上传仓库
-
cd shell
-
touch 123
-
git add .
-
git commit -m ‘zdsad’
-
git push -u origin master
-
rm -rf *
-
git clone git@10.18.47.23:/git-root/shell.git
[root@abc shell]# rm -rf * [root@abc shell]# git clone git@10.18.47.23:/git-root/shell.git 正克隆到 'shell'... git@10.18.47.23's password: remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) 接收对象中: 100% (6/6), done. [root@abc shell]# ls shell [root@abc shell]# ls shell/ 123 test1.sh
-
-
客户端
-
gitlab
- 私有的git web服务器
Gitlab-LOGO
Gitlab部署
-
system
- 支持的类UNIX系统
- Ubuntu
- Debian
- CentOS
- Red Hat Enterprise Linux (please use the CentOS packages and instructions)
- Scientific Linux (please use the CentOS packages and instructions)
- Oracle Linux (please use the CentOS packages and instructions)
- 不支持的类UNIX系统
- OS X
- Arch Linux
- Fedora
- Gentoo
- FreeBSD
- 支持的类UNIX系统
-
官网链接
- https://about.gitlab.com/downloads/#centos7
-
1、 Install and configure the necessary dependencies
- 4G以上内存
- yum install -y curl policycoreutils openssh-server openssh-clients
- 安装和配置必要的依赖关系
- curl 浏览器程序
- policycoreutils 加密程序
- openssh 远程登录程序
- systemctl enable sshd
- 开机自启动ssh程序
- systemctl start sshd
- yum install postfix -y
- 安装邮件程序
- gitlab在注册的时候一定要用邮箱名才能识别
- systemctl enable postfix
- systemctl start postfix
- systemctl stop firewalld
- 防火墙关上!
- systemctl disable firewalld
-
2、Add the GitLab package server and install the package
- 上传gitlab安装rpm包
- 上传gitlab安装rpm包
-
提示
- 如果是zip压缩包,请使用解压才可以使用。
-
yum -y install gitlab-ce-9.1.0-ce.0.el7.x86_64.rpm
-
- 官网安装(略)
- curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
- 添加GitLab-YUM仓库到服务器
- script.rpm.sh
- gitlab_gitlab-ce.repo
- 添加GitLab-YUM仓库到服务器
- yum install gitlab-ce
- curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
- 官网安装(略)
-
3、 Configure and start GitLab
- gitlab-ctl reconfigure
- 自动配置文件权限,安装数据库….
- 提示!安装的时间会很长!!!
- gitlab-ctl reconfigure
-
4、Browse to the hostname and login
-
gitlab服务器的地址:http://192.168.229.11/
- GITLAB占用80端口,访问时直接访问IP就可以 (第一次会让你确认root账户登录的密码)
-
登录图示
-
-
创建8位新密码
-
然后使用root登录即可
-
欢迎界面
-
创建项目
-
推送SSH秘钥
- 1秘钥提示
- 1秘钥提示
-
粘贴这个地址,用于下载项目(文档容器)
-
http://root@bogon/root/8_2gitlab.git
-
2查看秘钥
-
生成秘钥
- ssh-keygen
- cat ~/.ssh/id_rsa.pub
-
3上传秘钥
-
4查看秘钥
-
5链接地址
-
- 用于命令行,或客户端程序进行下载使用。
- git@web.chenfuguo.cn:root/2401_nb.git
-
6使用gitlab
-
图形操作
- 上传文件到gitlab
- 1.newfile:先新建一个文件。 2.uploadfile:再上传即可。
- 1.newfile:先新建一个文件。 2.uploadfile:再上传即可。
- 上传文件到gitlab
-
-
下载文件到gitlab客户端
令行操作 -
1.域名解析
- vim /etc/hosts
- 192.168.145.15 bogon
-
2.克隆服务器的文件
- git config --global user.name “git”
- git config --global user.email “git@bogon”
- git clone git@bogon:root/8_1gitlab.git
- 注意您粘贴的地址中,使用了什么用户名。
3.上传文件
- 注意您粘贴的地址中,使用了什么用户名。
-
cd 2401_nb/
- 进入工作目录
-
echo 1234567 > 3333.sh
- 新建文件
-
git init
- 初始化
-
git remote add origin git@bogon:root/8_1gitlab.git
- 配置远程服务器地址
- 如果远程服务器配置报错,因为之前已经配置过其他远程服务器。可以用命令清除掉
- git remote rm origin
-
git add .
- 建立当前文件夹下所有的文件,为准备上传的文件
-
git commit
- 提交上传说明
- git commit -m ‘本地仓库第一次上传’
-
git push -u origin master
- 只有第一次上传远程仓库需要使用 -u参数 第二次就不用了
- 上传
[root@web 8_1gitlab]# echo 4444 > 4.sh
[root@web 8_1gitlab]#
[root@web 8_1gitlab]#
[root@web 8_1gitlab]# git add .
[root@web 8_1gitlab]# gitm commit -m '本地仓库第二次上传'
bash: gitm: 未找到命令...
相似命令是: 'git'
[root@web 8_1gitlab]# git commit -m '本地仓库第二次上传'
[master 29db871] 本地仓库第二次上传
1 file changed, 1 insertion(+)
create mode 100644 4.sh
[root@web 8_1gitlab]#
[root@web 8_1gitlab]# git push origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 361 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@web.chenfuguo.cn:root/8_1gitlab.git
396989d..29db871 master -> master