使用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,操作更方便 ...
随机推荐
- openwrt procd
接着前面写过的一篇关于 procd 的笔记. procd 在 STATE_INIT 时会运行 /etc/inittab 中描述的几个级别指定程序. procd_inittab_run("re ...
- 树莓派wiringPi经常使用的函数介绍
1.void pinMode (int pin, int mode) ; 这个函数式设置pin脚的输入和输出模式以及PWM的输入和输出模式.在wiringPi中仅仅有 pin 1 (BCM_GP ...
- 【iOS系列】-自定义Modar动画
[iOS系列]-自定义Modar动画.md 我们需要做的最终的modar动画的效果是这样的, 就是点击cell,cell发生位移,慢慢的到第二个界面上的.为了做出这样的动画效果,我们需要以下的知识. ...
- WPF DataGrid获取选择行的数据
在WPF中,单击DataGrid,如何获取当前点击的行? 比如在MouseDoubleClick事件中,事实上获取的选中行是一个DataRowview,你可以通过以下的方法来获取选中行的数据,需要引用 ...
- UVA - 11019 Matrix Matcher hash+KMP
题目链接:传送门 题解: 枚举每一行,每一行当中连续的y个我们hash 出来 那么一行就是 m - y + 1个hash值,形成的一个新 矩阵 大小是 n*(m - y + 1), 我们要找到x*y这 ...
- SELECT INSTR(120,0000); 真
sql 排故 SELECT INSTR(120,0000); 真
- VC FTP服务器程序分析(一)
想在QT上移植一个FTP服务器程序,先学习windows下的FTP服务器例子,然后随便动手写点东西. 在pudn上搜索 "FTP服务器端和客户端实现 VC“这几个关键字,就可以搜到下面要分析 ...
- FZU1977 Pandora adventure —— 插头DP
题目链接:https://vjudge.net/problem/FZU-1977 Problem 1977 Pandora adventure Accept: 597 Submit: 2199 ...
- CentOS设置代理
假设我们要设置代理为 IP:PORT1.网页上网网页上网设置代理很简单,在firefox浏览器下 Edit-->>Preferences-->>Advanced--> ...
- putty与emacs
win环境下putty登录到linux并使用emacs时,需要折腾好配置才能正常工作.下面是折腾过程中碰到的问题与解决步骤: 1)要在putty控制台中启用鼠标,只需要在.emacs配置文件中启用xt ...