一、介绍

  1. 一、Git是什么(what)版本迭代
  2. Git是分布式版本控制系统,与SVN类似的集中化版本控制系统相比,
  3. 集中化版本控制系统如果中央服务器宕机则会影响数据和协同开发

image.png

能够对文件版本控制和多人协作开发
拥有强大的分支特性,所以能够灵活地以不同的工作流协同开发
分布式版本控制系统,即使协作服务器宕机,也能继续提交代码或文件到本地仓库,
当协作服务器恢复正常工作时,再将本地仓库同步到远程仓库

image.png


Workspace:工作区,就是你在电脑里能看到的目录
版本库:工作区有一个隐藏目录.git,这个不算工作区,而是Git的本地版本库,你的所有版本信息都会存在这里
Index / Stage:暂存区,英文叫 stage 或 index。一般存放在 ".git目录下" 下的 index 文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)
Repository:仓库区(或本地仓库)
Remote:远程仓库
master: 默认开发分支
origin: 默认远程版本库
https://blog.csdn.net/freeking101/article/details/90289202

二、安装与使用

# 1.安装git 
[root@localhost ~]# yum install -y git
git init:初始化一个git仓库
git clone:命令可以从Git仓库拷贝项目
git config:配置信息
git add:添加文件到缓存命令
git status:查看文件的状态命令
git diff:查看更新的详细信息命令
git commit:提交命令
git reset HEAD:取消缓存命令
git rm:删除命令
git mv:移动或重命名命令
git log :查看提交历史
  –oneline :查看历史记录的简洁版本
  –graph :查看历史中什么时候出现了分支、合并
  –reverse :逆向显示所有日志
  –author :查找指定用户的提交日志    
  –since、–before、 --until、–after: 指定帅选日期
  –no-merges :选项以隐藏合并提交

三、GitHub公有仓库

四、GitLab私有仓库

gitlab基本命令

gitlab-ctl reconfigure                 #重新加载配置文件
gitlab-ctl restart                     #重启gitlab

安装gitlib

1.安装依赖
yum -y install vim gcc gcc-c++ wget net-tools lrzsz iotop lsof iotop bash-completion
yum -y install curl policycoreutils openssh-server openssh-clients postfix

2.关闭防火墙Linux
systemctl disable firewalld
sed -i '/SELINUX/s/enforcing/disabled/' /etc/sysconfig/selinux

3.下载gitlib
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.4-ce.0.el7.x86_64.rpm --no-check-certificate
yum -y localinstall gitlab-ce-13.1.4-ce.0.el7.x86_64.rpm

3.编辑配置文件 改个默认端口 (82)
vim /etc/gitlab/gitlab.rb
    external_url 'http://192.168.11.103:82'
    nginx['listen_port'] = 82

gitlab-ctl reconfigure                 #重新加载配置文件
gitlab-ctl restart                     #重启gitlab

4.浏览器访问gitlab 
192.168.11.103:82

登录之后第一次要改密码
image.png
输入所改的密码 默认用户root
image.png

创建组与创建项目

image.png
image.png
image.png
组中创建项目
image.png
image.png

创建用户设置密码并将用户进入组

image.png
image.png
设置用户密码
image.png
image.png

设置用户进入组
image.png
image.png
image.png
退出登录测试张三用户
image.png

将项目源码推送到gitlab

[root@localhost ~]# yum install git -y
[root@localhost ~]# mkdir test/
[root@localhost test]#     git config --global user.name "Your Name"
[root@localhost test]#     git config --global user.email you@example.com
[root@localhost ~]# mkdir web
[root@localhost ~]# cd web
[root@localhost web]# git init
初始化空的 Git 版本库于 /root/web/.git/
[root@localhost web]# vim 1.html
[root@localhost web]# git add .
[root@localhost web]# git commit -m "v1"
[master(根提交) 9cdd148] v1
 1 file changed, 1 insertion(+)
 create mode 100644 1.html
[root@localhost web]# git remote add origin http://192.168.11.103:82/itmea_gtoup/web_itmea.git
[root@localhost web]# git push -u origin master
Username for 'http://192.168.11.103:82': zhangsan
Password for 'http://zhangsan@192.168.11.103:82': 
Counting objects: 3, done.
Writing objects: 100% (3/3), 204 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.11.103:82/itmea_gtoup/web_itmea.git
 * [new branch]      master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。

image.png