git 笔记

1.git
2.jenkins

gitlab 私有仓库,公司核心代码一般都会放在内网当中的额gitlab当中
github 公共仓库

redis
主从
高可用
redis-cluster


git可以在linux和windows当中使用


docker
dockerhub.com -- > github
harbor -- > gitlab
registry

安装git
1.在本地yum源当中直接下载即可
[root@ken1 ~]# yum install git -y


下载完成之后无需启动任何服务程序,直接使用

git常用选择:


add 把工作目录当中的文件添加到暂存区域
branch 查看及创建创建分支
checkout 版本回滚及切换分支
clone 把远程仓库克隆到本地
commit 把暂存区域文件提交到仓库
init 初始化工作目录(初始化完成会生成一个隐藏目录.git)
log 查看版本提交信息
merge 合并分支内容
pull 拉取远程仓库
push 推送仓库到远程
reset 版本回滚--》仓库版本回滚
status 查看文件状态


演示1:git使用

第一步:创建目录并初始化为git工作目录
[root@ken1 yum.repos.d]# cd /ken
[root@ken1 ken]# ls -a
. ..
[root@ken1 ken]# git init
Initialized empty Git repository in /ken/.git/
[root@ken1 ken]# ls -a
. .. .git


第二步:创建文件并提交
[root@ken1 ken]# git add .


第三步:提交到仓库
[root@ken1 ken]# git config --global user.email "you@example.com"
[root@ken1 ken]# git config --global user.name "Your Name"
[root@ken1 ken]#
[root@ken1 ken]# git commit -m "v1"


第四步:查看版本信息
[root@ken1 ken]# git log
commit 1618d8c812d8154bd296c0870deec07dd78b594d
Author: Your Name <you@example.com>
Date: Fri Nov 1 14:45:43 2019 +0800

v2

commit ade7ebea74ddcdd48c23cc9531aef1648556f540
Author: Your Name <you@example.com>
Date: Fri Nov 1 14:44:57 2019 +0800

v1
[root@ken1 ken]#


演示2:撤销工作目录当中的内容
第一步:修改一个已经提交过得文件内容
[root@ken1 ken]# echo 33 >> test


第二步:查看状态
[root@ken1 ken]# echo 33 >> test
[root@ken1 ken]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test
#
no changes added to commit (use "git add" and/or "git commit -a")

第三步:撤销工作目录当中的内容
[root@ken1 ken]# git checkout -- test
[root@ken1 ken]# git status
# On branch master
nothing to commit, working directory clean
[root@ken1 ken]# cat test
111
222

演示3:撤销缓存区的内容

第一步:修改一个已经提交过得文件内容
[root@ken1 ken]# echo 33 >> test


第二步:提交文件
[root@ken1 ken]# git add .

第三步:查看状态
[root@ken1 ken]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test
#

第四步:撤销暂存区内容
[root@ken1 ken]# git reset HEAD test
Unstaged changes after reset:
M test


第五步:撤销工作目录当中的内容
[root@ken1 ken]# git checkout -- test
[root@ken1 ken]# git status
# On branch master
nothing to commit, working directory clean
[root@ken1 ken]# cat test
111
222

演示4:

git reset --hard commitID


git分支

查看分支
创建分支
切换分支
合并分支


1.查看分支
[root@ken1 ken]# git branch
* master

2.创建分支
[root@ken1 ken]# git branch ken
[root@ken1 ken]# git branch
ken
* master


3.切换分支
[root@ken1 ken]# git checkout ken
Switched to branch 'ken'
[root@ken1 ken]# git branch
* ken
master

4.合并分支内容


第一步:切换分支
git checkout ken

第二步:修改文件并提交
echo ken >> test
git add .
git commit -m v4

第三步:切换至主分支
git checkout master

第四步:查看版本信息
git log #这里会发现没有ken分支创建的版本信息

第五步:合并分支
git merge ken

第六步:再次查看版本
git log

gitlab


1.部署搭建gitlab
第一步:上传gitlab的rpm安装包


第二步:安装gitlab
[root@ken1 ~]# rpm -ivh gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm
或者
yum localinstall gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm -y

第三步:修改gitlab配置文件
[root@ken1 ~]# vim /etc/gitlab/gitlab.rb
...
external_url 'http://192.168.64.5'
...

第四步:使配置重新生效
[root@ken1 ~]# gitlab-ctl reconfigure

第五步:浏览器访问
http://ip

第六步:修改密码
修改密码为8位以上的密码
登录账户:root


1.拉取项目
[root@ken1 test]# git clone http://192.168.64.5/root/test.git

2.提交文件之后进行推送

git push -u origin master #第一次推送需要指定-u 后续推送无需加

linux当中免密使用gitlab

1.ssh-keygen生成秘钥对
2.复制公钥/root/.ssh/id_rsa.pub
3.添加到gitlab --》 左上角三个横线 --》 profile settings --> ssh key
4.拉取的时候选择ssh地址
5.推送的时候无需密码

windows当中免密使用gitlab

原文地址:https://www.cnblogs.com/kittywerwer/p/11779075.html