gitlab的部署与应用

环境准备:

三台机器,一台做客户端(程序员上传代码用)192.168.1.10,一台做git服务器192.168.1.20,一台做jenkins 192.168.1.30

git: 分布式软件版本控制系统,独立使用的,

1.安装: yum -y install git

2.配置基本信息

git config --global user.name "Mr Zhao"      配置用户名

git config --global userr.email "[email protected]"   配置邮箱

git config --global core.editor vim           配置编辑器

3.查看信息

git config --list

cat  ~/.gitconfig   配置文件所在处,可以修改上面的基本信息

4. git的重要工作区域

工作区:编写代码的工作目录

暂存区:.git/index,工作区和版本库之间的缓冲地带,允许用户后悔的区域

版本库:工作区有一个.git目录,这个就是版本库

工作区 --git add --> 暂存区-->git commit-->版本库

5.创建仓库

方法一: 创建项目之初创建

git init mygit   

初始化空的 Git 版本库于 /root/mygit/.git/

方法二,在已存在的项目中创建版本库

mkdir myweb

cd myweb

echo "hello linux" > index.html

git init

初始化空的 Git 版本库于 /root/myweb/.git/

ls -A

.git  index.html

[root@client myweb]# git status -s
A  index.html
?? hosts
[root@client myweb]# git add .    #将所有文件提交到暂存区
[root@client myweb]# git status -s
A  hosts
A  index.html


从暂存区撤出hosts

[root@client myweb]# git rm --cached hosts
rm 'hosts'
[root@client myweb]# git status -s   撤出查看就变成了 ??
A  index.html
?? hosts

创建 .gitignore 忽略不需要加入到版本库的文件hosts

[root@client myweb]# echo hosts >> .gitignore

[root@client myweb]# echo .gitignore >> .gitignore
[root@client myweb]# cat .gitignore
hosts

.gitignore
[root@client myweb]# git status -s
A  index.html
6.提交到版本仓库

git commit   #直接敲会出现vim编辑器写日志,,如果是空白日志,终止提交,也就是上面所定义的core vim定义的

git commit -m "init data"

[root@client myweb]# git commit -m "init data"
[master(根提交) a8474aa] init data
 1 file changed, 1 insertion(+)
 create mode 100644 index.htmlecho hosts >> .gitignore
[root@client myweb]# git status
# 位于分支 master
无文件要提交,干净的工作区
7.删除工作区的文件并恢复:

[root@client myweb]# rm -rf index.html
[root@client myweb]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
#   (使用 "git add/rm <file>..." 更新要提交的内容)
#   (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
#    删除:      index.html
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

8.恢复删除的index.html

[root@client myweb]# git checkout -- index.html
[root@client myweb]# ls
hosts  index.html
9.从版本库删除文件

[root@client myweb]# git ls-files
hosts1
index.html
[root@client myweb]# git rm hosts1
rm 'hosts1'
[root@client myweb]# git ls-files
index.html

[root@client myweb]# git status
# 位于分支 master
# 要提交的变更:
#   (使用 "git reset HEAD <file>..." 撤出暂存区)
#
#    删除:      hosts1
#
10.彻底删除 (没有后悔药了)

[root@client myweb]# git commit -m "rm hosts1"
[master 9898403] rm hosts1
 1 file changed, 1 deletion(-)
 delete mode 100644 hosts1
[root@client myweb]# git status
# 位于分支 master
无文件要提交,干净的工作区
11.恢复误删除的文件(再通过版本库恢复找回来)

[root@client myweb]# git log
commit 98984031e3d15efe9d77ed81a9f8c6aaa40c7ed3
Author: Mr.Zhao <[email protected]>
Date:   Mon Nov 18 11:52:21 2019 +0800



commit aedf50f5a42a93aa930d6888946e4aa8b3fff863
Author: Mr.Zhao <[email protected]>
Date:   Mon Nov 18 11:49:39 2019 +0800


[root@client myweb]# git checkout aedf50f5a42a93aa930d6888946e4aa8b3fff863
Note: checking out 'aedf50f5a42a93aa930d6888946e4aa8b3fff863'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD 目前位于 aedf50f... hosts1
[root@client myweb]# ls
hosts1  index.html

git tag 标记

tag可以为模拟过一次设置标记

如将某一次提交设置为软件版本号

[root@client myweb]# git tag 2.0
[root@client myweb]# git tag
1.0
2.0
git 分支

git

[root@client myweb]# git add .
[root@client myweb]# git commit -m "add passwd"
# 头指针分离自 a8474aa
无文件要提交,干净的工作区
[root@client myweb]# ls
hello  index.html  passwd
[root@client myweb]# git checkout b1
切换到分支 'b1'
[root@client myweb]# ls
hello  index.html  passwd
[root@client myweb]# git checkout b1
切换到分支 'b1'
[root@client myweb]# ls
hello  index.html  passwd
[root@client myweb]# git checkout master
切换到分支 'master'
[root@client myweb]# ls
index.html
[root@client myweb]# git branch 查看分支
git branch 查看分支
[root@client myweb]# git rm passwd
rm 'passwd'
[root@client myweb]# git commit -m *
[master aecac25] *
 5 files changed, 24 deletions(-)
 delete mode 100644 a.txt
 delete mode 100644 hello
 delete mode 100644 hi.txt
 delete mode 100644 index.html
 delete mode 100644 passwd
[root@client myweb]# git status
# 位于分支 master
无文件要提交,干净的工作区


猜你喜欢

转载自www.cnblogs.com/luwei0915/p/11882057.html