使用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,操作更方便 ...
随机推荐
- HDU2489 Minimal Ratio Tree 【DFS】+【最小生成树Prim】
Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 全志Android SDK编译详解(一)
1.编译环境说明 Linux 服务器(任意电脑都可以,建议选择配置高的)安装ubuntu 10.04 作为编译的主机,其他开发者在xp 下,通过SSH/Telent 等协议登录linux 主机进行编. ...
- LeetCode(38)题解: Count and Say
https://leetcode.com/problems/count-and-say/ 题目: The count-and-say sequence is the sequence of integ ...
- python day 13 生成器 以及 推导式
1.生成器的本质是迭代器 2.生成器函数 def fn() 函数体 yield fn() g = fn() 此时这个g就是生成器 所以g 是可迭代的 g._ _next_ _ 每执行一次_ _nex ...
- 中断线程Interrupt()
以下是参考<<Java多线程模式>>的 1. sleep() & interrupt() 线程A正在使用sleep()暂停着: Thread.sleep(100000) ...
- JSON和JavaScript对象
var obj={width:100,height:200},这样的并不叫JSON,并且JSON只是一种数据格式,并不是具体的实例. 但很多人把这样的JS对象当成JSON,下面把这个问题讲清楚 一.J ...
- goroutine pool,WaitGroup,chan 示例
服务端高并发编程经常需要写很多goroutine来服务每一个连接,如何正确使用goroutine池是又拍云的工程师们需要考虑的问题,今天这篇文章,分享给同样需要使用go语言的小伙伴们. 文/陶克路 本 ...
- mysql 中varchar(50)最多能存多少个汉字
首先要确定mysql版本4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放 ...
- codeforces 441B. Valera and Fruits 解题报告
题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...
- html5--6-44信纸设计
html5--6-44信纸设计 实例 <!doctype html> <html> <head> <meta charset="utf-8" ...