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/

初始化版本仓库完成,在服务器上开放至少一种支持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

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 <file>..." 更新要提交的内容)

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

#

#修改:      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、欢迎加入技术交流


©著作权归作者所有:来自51CTO博客作者mob604756e834f7的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. OpenKruise v0.8.0 版本发布:K8s 社区首个规模化镜像预热能力
  2. IDEA2019.2版本最新破解到2089年,亲测可用
  3. Windows10 20H2 IT维护人员感兴趣的一些功能
  4. django1.8数据迁移
  5. Spring Cloud Gateway 扩展支持多版本控制及灰度发布
  6. kafka查看版本
  7. MGR用哪个版本?5.7 vs 8.0
  8. MySQL产品的生命周期
  9. MySQL 数据库事务及隔离级别,多版本控制

随机推荐

  1. golang iota从几开始
  2. golang如何升级?
  3. golang ide有哪些
  4. golang读取文本乱码解决方法
  5. golang http怎么使用
  6. erlang和golang的区别
  7. go语言网络编程、http处理流程详情
  8. golang gopath如何设置
  9. docker为什么用golang开发
  10. Go安装各种第三方库、包的命令