使用Git分布式版本控制系统
-
GIT(分布式版本控制系统)
使用Git服务程序
在正式使用前,我们还需要弄清楚Git的三种重要模式,分别是已提交、已修改和已暂存:
已提交(committed):表示数据文件已经顺利提交到Git数据库中。
已修改(modified):表示数据文件已经被修改,但未被保存到Git数据库中。
已暂存(staged):表示数据文件已经被修改,并会在下次提交时提交到Git数据库中。
提交前的数据文件可能会被随意修改或丢失,但只要把文件快照顺利提交到Git数据库中,那就可以完全放心了,流程为:
1.在工作目录中修改数据文件。
2.将文件的快照放入暂存区域。
3.将暂存区域的文件快照提交到Git仓库中。
主机名称 操作系统 IP地址
GIT服务器 Centos 192.168.126.137
GIT客户端 Centos 192.168.126.138
[root@accommate ~]# yum install -y git
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分安装过程………………
Installing:
git x86_64 1.8.3.1-4.el7 rhel7 4.3 M
Installing for dependencies:
perl-Error noarch 1:0.17020-2.el7 rhel7 32 k
perl-Git noarch 1.8.3.1-4.el7 rhel7 52 k
perl-TermReadKey x86_64 2.30-20.el7 rhel7 31 k
………………省略部分安装过程………………
Complete! 然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@accommate ~]# mkdir accommate.git
修改Git版本仓库的所有者与所有组:
[root@accommate ~]# chown -Rf git:git accommate.git/
初始化Git版本仓库:
[root@accommate ~]# cd accommate.git/
[root@accommate accommate.git]# git --bare init
Initialized empty Git repository in /root/accommate.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@localhost /]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
b0::b6:::ad:a3:f0::a8:b6:f4:e5:d8:: root@localhost.localdomain
The key's randomart image is:
+--[ RSA ]----+
| |
| |
| o o |
| . = = . |
| . S + |
| . o |
| .. o=.Eo |
|.o. ===. . |
|o..o oo |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@localhost /]# ssh-copy-id 192.168.126.137
The authenticity of host '192.168.126.137 (192.168.126.137)' can't be established.
ECDSA key fingerprint is 0a::0f::fb:0e::f7::9b::::b7::.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.126.137's password: Number of key(s) added: Now try logging into the machine, with: "ssh '192.168.126.137'"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@localhost /]# git clone root@192.168.126.137:/accommate.git
Cloning into 'accommate'...
warning: You appear to have cloned an empty repository.
向Git版本仓库提交一个新文件:
[root@localhost accommate]# echo "I successfully cloned the Git repository" > readme.txt
[root@localhost accommate]# git add readme.txt
[root@localhost accommate]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: readme.txt
#
[root@localhost accommate]# git commit -m "Clone the Git repository"
[master (root-commit) 1709f48] Clone the Git repository
file changed, insertion(+)
create mode readme.txt
[root@localhost accommate]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@localhost accommate]# git remote add server root@192.168.126.137:/accommate.git
将文件提交到远程Git服务器吧:
[root@localhost accommate]# git push -u server master
Counting objects: , done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To root@192.168.126.137:/accommate.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@localhost accommate]# cd ../Desktop
[root@localhost accommate Desktop]# git clone root@192.168.10.10:/root/accommate.git
Cloning into 'accommate'...
remote: Counting objects: , done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), done.
[root@linuxprobe Desktop]# cd accommate/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
使用Git分布式版本控制系统的更多相关文章
- GIT分布式版本控制系统
Git诞生历史 我想大家还记得Linus torvalds在1991年时发布了Linux操作系统吧,从那以后Linux系统变不断发展壮大,因为Linux系统开源的特性,所以一直接受着来自全球Linux ...
- Git ——分布式版本控制系统
Git ——分布式版本控制系统 本人git主页地址:https://github.com/lendoon/test.git git使用心得:初次接触git在课堂上,老师给我们提供了一个代码托管的场所, ...
- 手把手教你玩转Git分布式版本控制系统! (转载)
目录 Git诞生历史 Git环境准备 Git安装部署 Git常用命令 Git基本操作 Git管理分支结构 Git管理标签 GitLab安装部署 GitHub托管服务 Git客户端工具 Git诞生历史 ...
- 手把手教你玩转Git分布式版本控制系统!
目录 Git诞生历史 Git环境准备 Git安装部署 Git常用命令 Git基本操作 Git管理分支结构 Git管理标签 GitLab安装部署 GitHub托管服务 Git客户端工具 1 Git诞生历 ...
- g4e基础篇#2 Git分布式版本控制系统的优势
g4e 是 Git for Enterprise Developer的简写,这个系列文章会统一使用g4e作为标识,便于大家查看和搜索. 章节目录 前言 1. 基础篇: 为什么要使用版本控制系统 Git ...
- GIT 分布式版本控制系统的简单使用介绍
GIT 分布式版本控制系统的简单使用介绍 1.GIT的概念Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 与 SVN 区别:1. GIT不仅仅是个版本控制系统,它 ...
- 《Linux就该这么学》自学笔记_ch21_使用Git分布式版本控制系统
<Linux就该这么学>自学笔记_ch21_使用Git分布式版本控制系统 文章主要内容: 分布式版本控制系统 使用Git服务程序 提交数据 移除数据 移动数据 历史记录 还原数据 管理标签 ...
- 开发效率优化之Git分布式版本控制系统(一)
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将先从Git分布式版本控制系统来阐述开发效率优化 一,企业 ...
- Git分布式版本控制系统(下)
Git分布式版本控制系统(下) 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方便 ...
- Git分布式版本控制系统(上)
Git分布式版本控制系统(上) 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方便 ...
随机推荐
- requirejs中的define
关于requirejs中的define的原理理解 我们已经了解到模块模式是为单例创建私有变量和特权方法的.一个最基本的例子: var foo=(function(){ var something= ...
- iOS之UI--使用SWRevealViewController 实现侧边菜单功能详解实例
iOS之UI--使用SWRevealViewController 实现侧边菜单功能详解实例 使用SWRevealViewController实现侧边菜单功能详解 下面通过两种方法详解SWReveal ...
- java接口的一些想法
最近一直在闷头往前看<thingking in java> ,但是却由于赶了进度而忘记了初衷.当学到集合的时候,回头却发现,我连最基本的接口都不明白.查了一上午资料,现在明白例如一点点,写 ...
- iOS UIButton选中状态切换
UIButton*payBtn = [UIButtonbuttonWithType:UIButtonTypeCustom]; payBtn.frame=CGRectMake(size.width-24 ...
- Python开发【2.2 异常处理】
1.Python常见异常类型: Exception 常规错误的基类 AttributeError 对象没有这个属性 IOError 输入/输出操作失败 IndexError 序列中没有此索引(inde ...
- C/C++用状态转移表联合函数指针数组实现状态机FSM
状态机在project中使用很的频繁,有例如以下常见的三种实现方法: 1. switch-case 实现.适合简单的状态机. 2. 二维状态表state-event实现.逻辑清晰.可是矩阵通常比較稀疏 ...
- Html.Partial
老革命永远都在遇上各种似是而非的老问题. 这次,是这个Html.Partial,分部页. Html.Partial与Html.Action有啥区别呢?区别就是,Html.Partial只有一个视图,而 ...
- Class.forName("java.lang.String")的作用?
返回字节码: 返回的方式有2种: 第一种是这个类的字节码已经加载到内存里面来了,现在想要取到它的字节码,我直接找到那份字节码把他返回: 第二种是我去得到这个类的字节码,结果在虚拟机里面还没有这个类的字 ...
- Android开发环境搭建时遇到问题的解决方法
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/linux_loajie/article/details/33823637 Android开发环境搭建 ...
- Android 单击跳转到打电话发短信界面,长按打电话发短信
<uses-permission android:name="android.permission.CALL_PHONE"/><uses-permission a ...