一、git与SVN的对比【面试】

  ①git是分布式的,SVN是集中式的(最核心)

  ②git是每个历史版本都存储完整的文件,便于恢复,SVN是存储差异文件,历史版本不可恢复(核心)

  ③git可离线完成大部分操作,SVN则不能

  ④git有着更优雅的分支和合并实现。

  ⑤git有着更强的撤销修改和修改历史版本的能力。

  ⑥git速度更快,效率更高。

  基于以上几点,git有了很明显的优势,特别是他具有本地的仓库。

二、git的几个概念【面试】

  ①工作目录:工作目录是对项目的某个版本独立提取出来的内容。这些从 Git 仓库的压缩数据库中提取出来的文件,放在磁盘上供你使用或修改。

  ②暂存区域:是一个文件,保存了下次将提交的文件列表信息,一般在 Git 仓库目录中。有时候也被称作`‘索引’’,不过一般说法还是叫暂存区域。

  ③仓库工作目录:是Git 用来保存项目的元数据和对象数据库的地方。这是 Git 中最重要的部分,从其它计算机克隆仓库时,拷贝的就是这里的数据。

三、git工作流程

  在工作目录中修改文件 > 暂存文件,将文件的快照放入暂存区域 > 提交更新,找到暂存区域的文件,将快照永久性存储到 Git 仓库目录。(

如果 Git 目录中保存着的特定版本文件,就属于已提交状态。如果作了修改并已放入暂存区域,就属于已暂存状态。如果自上次取出后,作了修改但还没有放到暂存区域,就是已修改状态。)

四、安装(yum安装与编译安装)

yum安装: yum install -y git

编译安装:http://xin.kendd.cn/?p=253

五、git常用操作

  git add      添加文件至缓存区域

  git branch      查看分支和创建分支  git branch jam(创建jam分支)

  git checkout     进行撤销也可以进行分支切换  git checkout jam(切换jam分支)

  git clone        克隆远程主机仓库

  git commit     把暂存区的文件提交到仓库中

  git init           初始化目录(工作目录)

  git merge      合并分支

  git pull        拉取远程主机的仓库

  git push     把本地仓库推送到远程主机

  git reset     撤销

  git log        查看所有仓库

  git status     查看git目录中文件的状态

六、git常用演示

  ①git使用演示   

[root@localhost ~]# mkdir jam          #创建目录jam
[root@localhost ~]# cd jam #切换到jam目录下
[root@localhost jam]# git init #初始化目录为git工作目录
Initialized empty Git repository in /root/jam/.git/
[root@localhost jam]# touch test #创建文件
[root@localhost jam]# echo 'hello,world' >> test #写入内容
[root@localhost jam]# git add . #提交当前目录下的所有文件
[root@localhost jam]# git commit -m v1
[master (root-commit) 79ca1b2] v1
file changed, insertion(+)
create mode test
[root@localhost jam]# git status #查看git目录下的文件状态
# On branch master
nothing to commit, working directory clean
[root@localhost jam]# git log #查看所有本地仓库
commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date: Thu May :: - v1
[root@localhost jam]# echo 'jamhisao' >> test #再次写入内容
[root@localhost jam]# git add . #提交
[root@localhost jam]# git commit -m v2
[master f62e8df] v2
 1 file changed, 1 insertion(+)
[root@localhost jam]# git log #查看仓库
commit f62e8df90d59dfc3424ac38da4b5d4b07b2ea82b
Author: Your Name <you@example.com>
Date:   Thu May 23 09:37:52 2019 -0400     v2 commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date:   Thu May 23 09:32:45 2019 -0400     v1
[root@localhost jam]# git reset --hard 79ca1b2e870 #回滚到v1
HEAD is now at 79ca1b2 v1
[root@localhost jam]# cat test
hello,world

  ②撤销工作区的内容

[root@localhost jam]# git status         #查看当前文件状态
# On branch master
nothing to commit, working directory clean
[root@localhost jam]# echo 'now jam is here beijing' >> test
[root@localhost jam]# cat test #编辑当前文件并查看
hello,world
now jam is here beijing
[root@localhost jam]# git add . #提交
[root@localhost jam]# git commit -m v2
[master 25b8377] v2
file changed, insertion(+)
[root@localhost jam]# git log #查看仓库
commit 25b8377377722043fa4dd9b79c0223bb036c51b6
Author: Your Name <you@example.com>
Date: Thu May :: - v2 commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date: Thu May :: - v1
[root@localhost jam]# git reset --hard 79ca1b2e870763dd #撤销工作内容
HEAD is now at 79ca1b2 v1
[root@localhost jam]# git log
commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date: Thu May :: - v1
[root@localhost jam]# git status #查看当前文件状态
# On branch master
nothing to commit, working directory clean

  ③撤销暂存区文件(每执行一步都得查看状态)

[root@localhost jam]# cat test   #查看初始文件内容,并查看文件状态
hello,world
jam jam jam hahahha
[root@localhost jam]# git status
# On branch master
nothing to commit, working directory clean
[root@localhost jam]# echo 'hahahahahahahaha' >> test #编辑文件并查看状态
[root@localhost jam]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@localhost jam]# git add . #提交文件并查看状态
[root@localhost jam]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test
#
[root@localhost jam]# git reset HEAD test #回撤到工作区并查看状态
Unstaged changes after reset:
M test
[root@localhost jam]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: test
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@localhost jam]# git checkout -- test #撤销工作区的文件并查看状态
[root@localhost jam]# git status
# On branch master
nothing to commit, working directory clean
[root@localhost jam]# cat test #查看文件内容
hello,world
jam jam jam hahahha

  ④回滚到任意版本的操作演示

[root@localhost jam]# git reflog                #查看本地所有仓库
5d0fe77 HEAD@{}: reset: moving to 5d0fe77
f2dd664 HEAD@{}: commit: v4
5d0fe77 HEAD@{}: commit: v3
79ca1b2 HEAD@{}: reset: moving to 79ca1b2e870763dd
25b8377 HEAD@{}: commit: v2
79ca1b2 HEAD@{}: reset: moving to 79ca1b2e870
f62e8df HEAD@{}: commit: v2
79ca1b2 HEAD@{}: commit (initial): v1
[root@localhost jam]# echo '' >> test #提交多个仓库
[root@localhost jam]# git add .
[root@localhost jam]# git commit -m v6
[master 9e7c573] v6
file changed, insertion(+)
[root@localhost jam]# echo '' >> test
[root@localhost jam]# git add .
[root@localhost jam]# git commit -m v7
[master f1591dc] v7
file changed, insertion(+)
[root@localhost jam]# git log #查看本地所有仓库
commit f1591dcf316e51a5c7d6bef3df8e58791e65beaa
Author: Your Name <you@example.com>
Date: Thu May :: - v7 commit 9e7c573a8c8cdd48df4383686d4e5b67ebd57477
Author: Your Name <you@example.com>
Date: Thu May :: - v6 commit 5d0fe77ad291a1d832ba8dd6f5c4fd665199294c
Author: Your Name <you@example.com>
Date: Thu May :: - v3 commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date: Thu May :: - v1
...skipping...
[root@localhost jam]# git reset --hard 5d0fe77ad291a1 #回滚到v3仓库
HEAD is now at 5d0fe77 v3
[root@localhost jam]# git log #查看本地所有仓库
commit 5d0fe77ad291a1d832ba8dd6f5c4fd665199294c
Author: Your Name <you@example.com>
Date:   Thu May 23 20:29:45 2019 -0400     v3 commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date:   Thu May 23 09:32:45 2019 -0400     v1
[root@localhost jam]# git reflog #查看历史仓库的信息
5d0fe77 HEAD@{0}: reset: moving to 5d0fe77ad291a1
f1591dc HEAD@{1}: commit: v7
9e7c573 HEAD@{2}: commit: v6
5d0fe77 HEAD@{3}: reset: moving to 5d0fe77
f2dd664 HEAD@{4}: commit: v4
5d0fe77 HEAD@{5}: commit: v3
79ca1b2 HEAD@{6}: reset: moving to 79ca1b2e870763dd
25b8377 HEAD@{7}: commit: v2
79ca1b2 HEAD@{8}: reset: moving to 79ca1b2e870
f62e8df HEAD@{9}: commit: v2
79ca1b2 HEAD@{10}: commit (initial): v1
[root@localhost jam]# git reset --hard f2dd664 #回滚到历史v4
HEAD is now at f2dd664 v4
[root@localhost jam]# git log
commit f2dd6646c3e711f8d81ce4cd00e90b6d3babff70
Author: Your Name <you@example.com>
Date:   Thu May 23 20:31:27 2019 -0400     v4 commit 5d0fe77ad291a1d832ba8dd6f5c4fd665199294c
Author: Your Name <you@example.com>
Date:   Thu May 23 20:29:45 2019 -0400     v3 commit 79ca1b2e870763dd017978abb75d9985322bd5c1
Author: Your Name <you@example.com>
Date:   Thu May 23 09:32:45 2019 -0400     v1

  ⑤分支查看、分支、切换(重点),及其演示操作(分支对主线无影响)

[root@localhost jam]# cat test
hello,world
[root@localhost jam]# git branch #查看分支
* master
[root@localhost jam]# git branch jam #创建jam分支
[root@localhost jam]# git branch
jam
* master
[root@localhost jam]# git checkout jam #切换分支jam
Switched to branch 'jam'
[root@localhost jam]# git branch
* jam
master
[root@localhost jam]# echo '' >> test 编辑文件并提交查看
[root@localhost jam]# git add .
[root@localhost jam]# git commit -m v8
[jam ] v8
file changed, insertion(+)
[root@localhost jam]# cat test
hello,world [root@localhost jam]# git checkout master #切换分支master
Switched to branch 'master'
[root@localhost jam]# cat test #查看文件内容
hello,world
[root@localhost jam]# git merge jam #合并分支(master和jam)
Updating 79ca1b2..
Fast-forward
test | +
file changed, insertion(+)
[root@localhost jam]# cat test #查看文件发现jam分支的内容已合并到master
hello,world

git介绍以及常用命令操作的更多相关文章

  1. Git笔记:Git介绍和常用命令汇总

    Git 是一个开源的分布式版本控制系统,与 CVS, Subversion 等不同,它采用了分布式版本库的方式,不需要服务器端软件支持. 工作流程 Git 的工作流程大致如下: 克隆 Git 资源作为 ...

  2. git介绍及常用命令

    Git简介 linus 用C语言编写 2005年诞生 分布式版本管理系统 速度快,适合大规模,跨地区多人协同开发 分布式管理 Git 生态 Git 分布式版本管理系统 Gitlab git私库解决方案 ...

  3. git介绍和常用命令总结

    git中经常用的命令就是以下六个: 以下是命令总结: 另外,自己碰到的问题及解决方法: 在分支内提交远程仓库,-am: revert后进入vim,一直按住esc ,再连续按大写的z两次就退出来了: g ...

  4. Git介绍及常用操作演示(一)--技术流ken

    Git介绍 Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发 ...

  5. CI 知识 :Git介绍及常用操作

    Git介绍 Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发 ...

  6. Git的一些常用命令

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 简单的说就是托管代码的便于多人开发的管理系统. 二.Git的一些命令,我详细的说一下 我是基于github给大家说一下git的一些常 ...

  7. git介绍和常用指令

    Git介绍和常用指令 介绍:Git和SVN一样都是版本控制工具.不同的是Git是分布式的,SVN是集中式的.Git开始用可能感觉难点,等你用习惯了你就会觉得svn是有点恐怖.(如果一个项目有好多人一起 ...

  8. Linux的简单介绍和常用命令的介绍

    Linux的简单介绍和常用命令的介绍 本说明以Ubuntu系统为例 Ubuntu系统的安装自行百度,或者参考http://www.cnblogs.com/CoderJYF/p/6091068.html ...

  9. redis 介绍和常用命令

    redis 介绍和常用命令 redis简介 Redis 是一款开源的,基于 BSD 许可的,高级键值 (key-value) 缓存 (cache) 和存储 (store) 系统.由于 Redis 的键 ...

随机推荐

  1. Thymeleaf初探

    Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用 ...

  2. 【两种方式】vuex 如何监听页面状态的变化

    由于 Vuex 的状态存储本来就是响应式的,从 store 实例中读取状态最简单的方法,就是在计算属性中返回某个状态. 在 B 页面引入以下代码: computed: { myValue() { re ...

  3. Linux之yum软件管理

    YUM yum = Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包.它能自动解决包的倚赖性问题. 它能便于管理大量系统的更新问题 yum特点 *可以 ...

  4. Python模块struct(二进制数据服务)

    struct模块 Python没有专门处理字节的数据类型.但由于b'str'可以表示字节,所以,字节数组=二进制str. 而在C语言中,我们可以很方便地用struct.union来处理字节,以及字节和 ...

  5. 第七章 路由 71 路由-router-link的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  6. regex正则

    1 正则表达式基本语法 两个特殊的符号^和$.他们的作用是分别指出一个字符串的开始和结束.例子如下: ^The:表示所有以”The”开始的字符串(”There”,”The cat”等): of des ...

  7. TXNLP 20-33

    文本处理的流程 # encoding=utf-8 import jieba import warnings # 基于jieba的分词 seg_list = jieba.cut("贪心学院专注 ...

  8. 深入理解python协程

    目录 概述 生成器变形 yield/send yield send yield from asyncio.coroutine和yield from async和await 概述 由于 cpu和 磁盘读 ...

  9. CentOS 安装oracle client

    下载Oracle Client 1.通过下载地址下载 下载地址:https://www.oracle.com/database/technologies/instant-client/linux-x8 ...

  10. Linux硬盘安装步骤

    网上找了许多用DVD镜像硬盘安装FC5的文章,可是都不系统,为了全中国的广大菜鸟们,云计算架构师 抽了很多时间来写这篇详细的安装文章,希望对初次接触LINUX或者刚刚入门的朋友有所帮助. 一.预备知识 ...