git and gitlab code repository

1. Understanding of git

Distributed version control system
Insert picture description here
(1) Git features:
speed,
simple design
, strong support for non-linear development mode (allowing thousands of parallel development branches),
fully distributed
, capable of efficiently managing super-large-scale projects similar to the Linux kernel (Speed ​​and data volume)
git reference
(2) Git has three states: committed, modified, and staged.
Modified means that the file has been modified, but has not been saved in the database.
Staged means that the current version of a modified file is marked so that it will be included in the next snapshot.
Submitted means that the data has been safely stored in the local database.
(3) Only for plain text files, this will make our Git project have three stages: workspace, temporary storage area and Git directory
Insert picture description here

2. The use of git

1.安装Git:
yum install -y git
2.获取 Git 仓库通常有两种方式:
将尚未进行版本控制的本地目录转换为 Git 仓库
从其它服务器克隆 一个已存在的 Git 仓库。比如: git clone 
3.初始化版本库:
mkdir demo
cd demo/
[root@server1 demo]# git init
Initialized empty Git repository in /root/demo/.git/
[root@server1 demo]# l.
.  ..  .git  #.git目录是git跟踪管理版本库的
[root@server1 demo]# cd .git/
[root@server1 .git]# ls
branches  config  description  HEAD  hooks  info  objects  refs
4.用户信息
git config --global user.email "[email protected]"
git config --global user.name "xd"
5.检查当前文件状态
git status  #提示下一步可能要干什么
git status -s	 #简化输出
?? README.txt #新建文件,在工作区

Insert picture description here

[root@server1 demo]# git add README.txt  #跟踪新文件
[root@server1 demo]# git status -s  #注意位置,在git目录
A  README.txt  #add过的,在暂存区

git commit -m "add README.txt"  #添加描述提交更新
git commit -a -m "v2"  #跳过使用暂存区域

Insert picture description here
Insert picture description here
Cancel the temporary file
git reset HEAD README.txt
Insert picture description here
Undo the modification of the file
git checkout – README.txt
Insert picture description here

6.查看提交历史
git log
git reflog
git log --pretty=oneline  #完整的编号文件

Insert picture description here

7.忽略文件
[root@server1 demo]# cat .gitignore
.*  #忽略所有隐藏文件
dir1  #只忽略当前目录下的test文件

Insert picture description here
Insert picture description here
8. Remove the file
git rm README.txt
Insert picture description here
9. Version rollback
git reflog
git reset --hard 95ef771
Insert picture description here
10. Rename the file
git mv README.txt README
In fact, running git mv is equivalent to running the following three commands
mv README. txt README, git rm README.txt, git add README

2. Gitlab code repository

This is similar to the github usage method, the function is similar, but gitlab is deployed on the local
official website to download the
domestic download

软件安装: (官方推荐至少4G内存)
get gitlab-ce-13.2.2-ce.0.el7.x86_64.rpm
yum install gitlab-ce-13.2.2-ce.0.el7.x86_64.rpm 
cd /etc/gitlab/
vim gitlab.rb
  29 external_url 'http://172.25.2.1'  #访问gitlab的地址
  
gitlab-ctl  reconfigure  #重载服务,开机自启的
登录gitlab
http://172.25.2.1  #用户root 第一次登录需要强制修改密码

常用命令
gitlab-ctl start    		# 启动所有 gitlab 组件
gitlab-ctl stop        		# 停止所有 gitlab 组件
gitlab-ctl restart       	# 重启所有 gitlab 组件
gitlab-ctl status        	# 查看服务状态
gitlab-ctl reconfigure      # 重载服务
gitlab-ctl tail        		# 查看日志

Chinese settings
Insert picture description here
1. New warehouse project
Insert picture description here
2. Add ssh public key
ssh-keygen #Generate key
Insert picture description here
Insert picture description here
3. Clone
Insert picture description here
Insert picture description here
3. Upload
git push origin master
Insert picture description here
Insert picture description here
4. Add and delete remote projects
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_49564346/article/details/114693264
Recommended