GIT的详解及gitlab的使用

1、Git历史

       自2002年开始,林纳斯·托瓦兹决定使用BitKeeper作为Linux内核主要的版本控制系统用以维护代码。因为BitKeeper为专有软件,这个决定在社区中长期遭受质疑。在Linux社区中,特别是理查德·斯托曼与自由软件基金会的成员,主张应该使用开放源代码的软件来作为Linux核心的版本控制系统。林纳斯·托瓦兹曾考虑过采用现成软件作为版本控制系统(例如Monotone),但这些软件都存在一些问题,特别是性能不佳。现成的方案,如CVS的架构,受到林纳斯·托瓦兹的批评。

2005年,安德鲁·垂鸠写了一个简单程序,可以连接BitKeeper的存储库,BitKeeper著作权拥有者拉里·麦沃伊认为安德鲁·垂鸠对BitKeeper内部使用的协议进行逆向工程,决定收回无偿使用BitKeeper的授权。Linux内核开发团队与BitMover公司进行蹉商,但无法解决他们之间的歧见。林纳斯·托瓦兹决定自行开发版本控制系统替代BitKeeper,以十天的时间,编写出第一个git版本

2、git用来干什么?

      不知道你工作的时候有没有遇到这样的情况:

比如说,做BIM建模,你手中有一份模型初稿,但现在需要在上面进行修改。

1、你怕修改之后万一出现什么错误,把原来的文件也弄坏了;
2、你修改到一定程度,改错了,想撤销,但你不小心点了保存,保存之后是不能撤销的。

于是你不得不复制出一个副本,比如:

3、安装git

1 安装环境

首先关闭防火墙与selinux

[root@git ~]# rpm -qa centos-release
centos-release-7-4.1708.el7.centos.x86_64

2 Yum安装Git

centos 自带git

[root@git ~]# rpm -qa git
git-1.8.3.1-11.el7.x86_64

安装方法

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

4、初次运行 Git 前的配置

配置过程

[root@gitlab ~]# git config --global user.name "newrain"  #配置git使用用户
[root@gitlab ~]# git config --global user.email "newrain@aliyun.com"  #配置git使用邮箱
[root@gitlab ~]# git config --global color.ui true  #语法高亮
[root@gitlab ~]# git config --list # 查看全局配置
user.name=newrain
user.mail=newrain@aliyun.com
color.ui=true

1.获取帮助

使用Git时需要获取帮助,有三种方法可以找到Git命令的使用手册:

git help <verb>
git <verb> --help
man git-<verb>

例如,要想获得配置命令的手册,执行

git help config

5 、获取 Git 仓库(初始化仓库)

1、首先我们要创建一个裸(空的)库

 

 [root@gitlab ~]# useradd git
[root@gitlab ~]# passwd git
[root@gitlab ~]# mkdir /git-root/
[root@gitlab ~]# cd /git-root/
[root@gitlab git-root]# git init --bare shell.git
Initialized empty Git repository in /git-root/shell.git/
[root@gitlab git-root]# chown -R git:git shell.git

2、打开另一台服务器,也要关闭防火墙和selinux,还要下载git(和上面步骤一样)作为本地仓库使用

创建本地仓库

[root@gitlab opt]# ssh-keygen
[root@gitlab opt]# ssh-copy-id git@10.12.153.161
[root@gitlab opt]# git clone git@10.12.153.161:/git-root/shell.git
[root@gitlab opt]# ls
rh  shellcd
[root@gitlab opt]# cd shell/
[root@gitlab shell]# vim test1.sh (自己往文件随便写点东西)
[root@gitlab shell]# git add test1.sh
[root@gitlab shell]# git commit -m 'KX'
[master (root-commit) 33c5fbf] KX
 1 file changed, 2 insertions(+)
 create mode 100644 test1.sh
[root@gitlab shell]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@10.12.153.160:/git-root/shell.git
 * [new branch]      master -> master
[root@gitlab shell]# 
[root@git objects]# tree (在上一台机器的/root/shell/objects下运行)
[root@git objects]# tree
.
├── 0c
│   └── 48137336be8e3203660633517a1ad2aace8ffa
├── a0
│   └── 05da6d5b81ecdcc10d247c7f4c2c7f4ad1f059
├── c5
│   └── 1e7ee650766ca34b21cd852f5a628de8de3de0
├── info
└── pack

5 directories, 3 files

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值