Git 理论

版本控制是一种记录一个或若个文件内容变化,以便将来查阅特定版本修订情况的系统(记录代码文件的变化),采用版本控制系统(version control system—>VCS)你就可以将某个文件回溯到之前的状态,甚看,至将整个项目都回退到过去某个时间点的状态,你可以比较文件的变化细节,查出最后是谁修改了哪个地方,从而找出导致怪异问题出现的原因,又是谁在何时报告了某个功能缺陷等等,使用版本控制系统通常还意味着,就算你乱来一气把整个项目中的文件改的改删的删,你也照样可以轻松恢复到原先的样子,但额外增加的工作量却微乎其微

Git是一个分布式版本控制系统:记录项目代码

版本控制系统存在的方式(VCS version control system):
1.简单的VCS 单个数据库记录代码的内容变化
2.集中式的版本控制系统CVCS centralized version control system svn
3.分布式的版本控制系统DVCS distributed version control system
集中式的缺点是:单节点,会出现宕机的现象,不能及时处理

svn:

SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。互联网上很多版本控制服务已从CVS迁移到Subversion。说得简单一点SVN就是用于多个人共同开发同一个项目,共用资源的目的。

分布式VCS

git特点
1.直接记录快照,而非差异比较(不用比较差异)
2.Git一般只增加数据(拉取、上传代码)
3.Git保证代码完整性(git在每一次提交上传的时候,会比较远程仓库的信息校验和本地仓库的信息校验是否一样,一样的话继续上传,不一样停止上传,任何事情不可以绕开git操作)

git常规操作逻辑:
1.添加到暂存区add
2.添加到本地仓库commit(新写的代码)
3.上传到远程仓库push

SVN与Git的最主要的区别?

SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以首先要从中央服务器哪里得到最新的版本,然后干活,干完后,需要把自己做完的活推送到中央服务器。集中式版本控制系统是必须联网才能工作,如果在局域网还可以,带宽够大,速度够快,如果在互联网下,如果网速慢的话,就纳闷了。

Git是分布式版本控制系统,那么它就没有中央服务器的,每个人的电脑就是一个完整的版本库,这样,工作的时候就不需要联网了,因为版本都是在自己的电脑上。既然每个人的电脑都有一个完整的版本库,那多个人如何协作呢?比如说自己在电脑上改了文件A,其他人也在电脑上改了文件A,这时,你们两之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。

安装git

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

一、搭建本地仓库

[root@localhost ~]# mkdir /test
[root@localhost ~]# cd /test/
[root@localhost test]# git init  #将当前的目录作为本地仓库
初始化空的 Git 版本库于 /test/.git/
[root@localhost test]# ls -a
.  ..  .git

把代码上传到本地仓库

[root@localhost test]# vim test.py
#!/usr/bin/python
print("蚊子 小奥奥");
[root@localhost test]# git add test.py  #添加到暂存区
[root@localhost test]# git status #查看代码当前的状态
# 位于分支 master
#
# 初始提交
#
# 要提交的变更:
#   (使用 "git rm --cached <file>..." 撤出暂存区)
#
#   新文件:    test.py
[root@localhost test]# git commit -m "first" #提交到本地仓库
*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity.
Omit --global to set the identity only in this repository.fatal: unable to auto-detect email address (got 'root@localhost.(none)')

#注:再提交到本地之前就需要写上用户名和邮箱 如果不切换目录,用户名和邮箱只需要写一次,之后就默认使用这个邮箱和用户名

[root@localhost test]# vim test.py
#!/usr/bin/python
print("蚊子 小奥奥");
print("蚊子 果果牛");[root@localhost test]# git add test.py
[root@localhost test]# git config --global user.name "haha"
[root@localhost test]# git config --global user.email haha@161.com
[root@localhost test]# git commit -m "first"
[master(根提交) 028602e] first1 file changed, 3 insertions(+)create mode 100644 test.py

代码的回滚
1、在暂存区中回滚

#!/usr/bin/python
print("蚊子 小奥奥");
print("蚊子 果果牛");
#添加
print("1111");
[root@localhost test]# git add test.py
[root@localhost test]# git status
# 位于分支 master
# 要提交的变更:
#   (使用 "git reset HEAD <file>..." 撤出暂存区)
#
#   修改:      test.py
#
[root@localhost test]# git reset HEAD test.py #撤出暂存区
重置后撤出暂存区的变更:
M   test.py
[root@localhost test]# git checkout -- test.py  #回滚
[root@localhost test]# cat test.py  #可以看到刚刚添加的1111没有了
#!/usr/bin/python
print("蚊子 小奥奥");
print("蚊子 果果牛");

2、已经添加到本地仓库当中,进行回滚

[root@localhost test]# vim test.py  #添加代码用于验证
print("蚊子");
[root@localhost test]# git add test.py
[root@localhost test]# git commit -m "second"
[master 4ff75f0] second1 file changed, 1 insertion(+)[root@localhost test]# git log #查看git日志[root@localhost test]# git reset --hard  028602e28f8c78b1d4bf822e8db7bf8c1c95d7d5
HEAD 现在位于 028602e first
[root@localhost test]# cat test.py
#!/usr/bin/python
print("蚊子 小奥奥");
print("蚊子 果果牛");

3、删除本地仓库的文件

[root@localhost test]# git rm test.py
rm 'test.py'
[root@localhost test]# git commit -m "delete"
[master 71affa7] delete1 file changed, 3 deletions(-)delete mode 100644 test.py
[root@localhost test]# ls

二,远程仓库

https://github.com 注册账号

创建存储库:


1、本地仓库和远程仓库进行相连

[root@localhost test]# ssh-keygen #免密登录,直接四次回车即可
[root@localhost test]# cat /root/.ssh/id_rsa.pub  #查看生成的密钥
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyBxdelPAGJVA+y9F/lGyT8p7L2r2mR1h9V4eZGsEXICxgkz1ImJYmDDu52kgtPkxEFYtf2kG6gjCVF8Llt7J7sHsEz6/GUkATqb3VIZ1bMGgJdn8jcqckJRkdGSH/b3Lm88GQ84BgOdIUBdYqdAi7plbAOonGeFeRN87fqmUg0+NOBTXRGUwZfykU6YhyGNkd1KnR6rMZP04rW3zawYQmPXdDVHN/ppPY8pOzmzX1lxCjH/IwHf0FladpgidNvA5gIFJMrCv6nrZPzF+nwGrSpqfKbSUHUIEAJaexW3z1CubaqeODe/vG2p5UXNIWgnelVOmXFaRvKtuNu7O6UbVT root@localhost





2、上传代码到github

[root@localhost test]# systemctl stop firewalld
[root@localhost test]# setenforce 0
[root@localhost test]# ssh -T git@github.com  #联网登录
输入yes
[root@localhost test]# vim test.py
#!/usr/bin/python
print("小奥奥")
[root@localhost test]# git add test.py
[root@localhost test]# git commit -m "third"
[master ae14c9a] third1 file changed, 2 insertions(+)create mode 100644 test.py

[root@localhost test]# git remote add origin git@github.com:xiaoaoao123/renzihua.git
[root@localhost test]# git push -u origin master

查看github上面是否存在代码



3、在github上面下载代码

[root@localhost test]# mkdir /test1
[root@localhost test]# cd /test1/
[root@localhost test1]# ls

复制克隆代码

[root@localhost test1]# git clone git@github.com:xiaoaoao123/renzihua.git
正克隆到 'renzihua'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 8 (delta 0), reused 8 (delta 0), pack-reused 0
接收对象中: 100% (8/8), done.
[root@localhost test1]# ls
renzihua
[root@localhost test1]# cd renzihua/
[root@localhost renzihua]# ls
test.py

进行修改,然后上传

[root@localhost renzihua]# vim test.py
#!/usr/bin/python
print("小奥奥")
print("果果牛")
[root@localhost renzihua]# git add test.py
[root@localhost renzihua]# git config --global user.name "xixi"  #这个名字可以自定义
[root@localhost renzihua]# git config --global user.email xixi@123.com  #邮箱也是自定义即可
[root@localhost renzihua]# git commit -m "xixi"
[master a0ff5a7] xixi1 file changed, 1 insertion(+)
[root@localhost renzihua]# git push origin master #上传
………………
To git@github.com:xiaoaoao123/renzihua.gitae14c9a..a0ff5a7  master -> master

4、添加版本标签

[root@localhost renzihua]# pwd
/test1/renzihua
[root@localhost renzihua]# git tag v1.0.1  #这个版本号随意
[root@localhost renzihua]# git push origin v1.0.1
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:xiaoaoao123/renzihua.git* [new tag]         v1.0.1 -> v1.0.1
[root@localhost renzihua]# vim test.py
#!/usr/bin/python
print("小奥奥")
print("果果牛")
print("haha")
[root@localhost renzihua]# git add test.py
[root@localhost renzihua]# git commit -m "haha"
[master 9851f96] haha1 file changed, 1 insertion(+)
[root@localhost renzihua]# git push origin master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 277 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:xiaoaoao123/renzihua.gita0ff5a7..9851f96  master -> master
[root@localhost renzihua]# git tag v1.0.3
[root@localhost renzihua]# git push origin v1.0.3
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:xiaoaoao123/renzihua.git* [new tag]         v1.0.3 -> v1.0.3
[root@localhost renzihua]# git tag
v1.0.1
v1.0.3



5、分支

[root@localhost renzihua]# git branch
* master
[root@localhost renzihua]# git branch haha  #创建分支的名字,自定义
[root@localhost renzihua]# git branchhaha
* master[root@localhost renzihua]# git checkout haha  #切换分支
切换到分支 'haha'
[root@localhost renzihua]# git branch
* hahamaster[root@localhost renzihua]# vim test.py
#添加新的内容
#!/usr/bin/python
print("小奥奥")
print("果果牛")
print("haha")
print("sdbsddsf")
[root@localhost renzihua]# git add test.py
[root@localhost renzihua]# git commit -m "yy"  #在haha的分支中上传
[haha a76c80a] yy1 file changed, 1 insertion(+)
[root@localhost renzihua]# git checkout master  #切换到主干,发现没有修改
切换到分支 'master'
[root@localhost renzihua]# cat test.py
#!/usr/bin/python
print("小奥奥")
print("果果牛")
print("haha")[root@localhost renzihua]# git merge haha   #合并haha分支
更新 9851f96..a76c80a
Fast-forwardtest.py | 1 +1 file changed, 1 insertion(+)
[root@localhost renzihua]# cat test.py #查看代码发生修改
#!/usr/bin/python
print("小奥奥")
print("果果牛")
print("haha")
print("sdbsddsf")

Git(分布式版本控制系统)相关推荐

  1. Git 分布式版本控制系统

    目录 文章目录 目录 Git 分布式版本控制系统 Git 的基本概念 Git 的仓库结构 Git 的核心对象 Git 的数据结构 Git Flow 参考文档 Git 分布式版本控制系统 Git 是一个 ...

  2. g4e基础篇#2 Git分布式版本控制系统的优势

    1. 基础篇: 为什么要使用版本控制系统 Git 分布式版本控制系统的优势 Git 安装和设置 初始化Git存储库(Repo) 起步 1 – 创建分支和保存代码 起步 2 – 了解Git历史记录 起步 ...

  3. Git分布式版本控制系统(下)

    Git分布式版本控制系统(下) 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方便 ...

  4. Git分布式版本控制系统(上)

    Git分布式版本控制系统(上) 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方便 ...

  5. Git分布式版本控制系统

    Git分布式版本控制系统 git remote -v 查看仓库 一 企业高效持续集成平台场景介绍: 二,GIT分布式版本控制系统: 2.1 Git简介: 2.1.1 git是什么? Git在Wikip ...

  6. Git 分布式版本控制系统使用教程

    Git 专栏索引: Git 分布式版本控制系统使用教程 在 IDEA 中使用 Git 图文教程 Git 分布式版本操作系统使用教程 1. 版本控制系统简介 1.1 集中式版本控制系统 1.2 分布式版 ...

  7. 使用Git分布式版本控制系统

    GIT(分布式版本控制系统) Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理 ...

  8. git(2)---git 分布式版本控制系统

    集中式vs分布式 Linus一直痛恨的CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 先说集中式版本控制系统,版本库是集中存放在中央服务 ...

  9. Git分布式版本控制系统简介和使用

    Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.[1] Git的读音为/gɪt/. Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本 ...

  10. 22-07-14 西安 Git 分布式版本控制系统 、代码管理

    Git是目前世界上最先进的分布式版本控制系统,Git可以做源代码管理 Git的诞生 Linus (Linus Torvalds 林纳斯.托瓦斯)是在BitKeeper停止向开源社区提供免费版本后开发了 ...

最新文章

  1. 自动驾驶中的车道线跟踪技术
  2. npm切换到淘宝镜像
  3. 一天搞定HTML----列表标签03
  4. unity3d Vector3.Lerp解析
  5. PostgreSQL学习笔记7之函数和操作符三
  6. 模型和控制器-起步阶段
  7. bootstrap .col-md-6 文字居中问题处理
  8. 一文掌握关于Java数据结构所有知识点(欢迎一起完善) 1
  9. 利用Python发送短信,用处多多
  10. 使用VC6.0开发COM组件 - 傻瓜式,不讲理论,只讲实例
  11. 毕设日志——tensorboardX无法连接的问题
  12. Eclipse3.2安装简介
  13. CCS7.3 安装使用教程
  14. latex数学符号加粗_LaTex数学公式符号整理
  15. 12f的接线 esp8266_ESP8266固件升级方法(ESP8266-12F模组)
  16. Lync Server 服务器版本升级
  17. 低版本IE对于JSON数据的处理
  18. biostar来电自动开机_bios设置来电自动开机
  19. 倒计时,距离活动还有0天0时0分0秒
  20. 硬盘柱面损坏怎么办_硬盘0柱面损坏数据恢复(老牌数据恢复)

热门文章

  1. 左右箭头切换的tabs
  2. pygame 游戏开发 基础物理建模 重力系统模拟
  3. 桌面只计算机图标发白,Win7电脑桌面图标变成白色如何解决?
  4. 区块链技术发展趋势与银行业探索实践
  5. 什么是 Java 垃圾回收器~
  6. HPLC载波模块通信单元引脚定义
  7. Java小案例——方法实现简单登录注册
  8. 线下活动抽奖PHP源码,对接公众号,实现关注公众号发送关键字获取抽奖码,通过平台进行摇号抽奖,可以二次开发(所有公众号都可对接)
  9. 简单在线剪辑音乐工具分享
  10. Redis 知识点总结:为何使用reids、redis是什么、redis的优势、redis如何持久化