git merge 暂存区_Git简单部署

1、系统环境准备

192.168.20.40   master    git   gitlab

192.168.20.39   client      git

[root@k8s-master ~]# yum -y install git

[root@k8s-node3 ~]# yum -y install git

2、创建git版本仓库

[root@k8s-master ~]# mkdir  merge.git

[root@k8s-master ~]# useradd git

[root@k8s-master ~]# passwd git

[root@k8s-master ~]# chown -Rf git:git merge.git

[root@k8s-master ~]# cd merge.git/

[root@k8s-master merge.git]# git --bare init

Initialized empty Git repository in /root/merge.git/

2e205f95f8be08e5005a6954d5927c10.png

初始化版本仓库完成,在服务器上开放至少一种支持Git的协议,使用的是SSH协议,切换至Git客户机来生成SSH秘钥

[root@k8s-node3 ~]# ssh-keygen 

[root@k8s-node3 ~]# ssh-copy-id 192.168.20.40

[root@k8s-node3 ~]# git clone root@192.168.20.40:/root/merge.git

正克隆到 'merge'...

warning: 您似乎克隆了一个空版本库。

[root@k8s-node3 ~]# git config --global user.name "hahashen"

[root@k8s-node3 ~]# git config --global user.email hahashen@qq.com

[root@k8s-node3 ~]# git config --global core.editor vim 

[root@k8s-node3 ~]# git config --list

user.name=hahashen

user.email=hahashen@qq.com

core.editor=vim

0f800e8b6f89dee62f60e3ddc00e912d.png

3、Git只能追踪类似于,网页,程序源码等文本文件内容的变化,下面模拟代码提交的过程

[root@k8s-node3 ~]# cd merge/

[root@k8s-node3 merge]# echo "hahashen update" > index.html

将文件添加到暂存区

[root@k8s-node3 merge]# git add index.html 

添加到暂存区后再次修改文件的内容

[root@k8s-node3 merge]# echo "please tell me ">> index.html 

将暂存区的文件提交到git版本仓库,命令格式为“git commit -m ”提交说明

[root@k8s-node3 merge]# git commit -m "add the index file"

[master(根提交) 13625c0] add the index file

 1 file changed, 1 insertion(+)

 create mode 100644 index.html

查看当前工作目录的状态

[root@k8s-node3 merge]# git status

# 位于分支 master

# 尚未暂存以备提交的变更:

#   (使用 "git add ..." 更新要提交的内容)

#   (使用 "git checkout -- ..." 丢弃工作区的改动)

#

#修改:      index.html

#

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

(1)第一次修改提交代码:git 将代码文件提交到本地git版本数据库,此时会在暂存区生产一个快照版本

(2)第二次修改提交代码:当再次修改代码,需要重新提交到暂存区,此时还会生产一个快照版本

(3)提交代码:只有将暂存区的代码提交到Git版本数据库才能算真正提交

查看当前文件内容与Git版本数据库中的差别

[root@k8s-node3 merge]# git diff index.html 

diff --git a/index.html b/index.html

index 095b90b..2441711 100644

--- a/index.html

+++ b/index.html

@@ -1 +1,2 @@

 hahashen update

+please tell me 

把文件提交Git版本数据库

[root@k8s-node3 merge]# git add index.html 

查看下当前git版本仓库的状态

[root@k8s-node3 merge]# git commit -m "added update"

[master 8a3a1d8] added update

 1 file changed, 1 insertion(+)

4、这次的操作还是只将文件提交到了本地的git仓库,并没有推送带远程的Git服务器,所有需要定义远程的git服务器

[root@k8s-node3 merge]# git remote add server root@192.168.20.40:/root/merge.git

[root@k8s-node3 merge]# git push -u server master

Counting objects: 6, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (6/6), 462 bytes | 0 bytes/s, done.

Total 6 (delta 0), reused 0 (delta 0)

To root@192.168.20.40:/root/merge.git

 * [new branch]      master -> master

分支 master 设置为跟踪来自 server 的远程分支 master。

相关推荐:

1、Git版本控制

2、简易Git服务器gogs的搭建

3、欢迎加入技术交流

1f5c7376d348613193d3fdac52e6e4c9.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值