一、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. Linux根文件系统和目录结构及bash特性3

    bash的基础特性: 命令补全:        shell程序在接收到用户执行命令的请求,分析完成之后,最左侧的字符串会被当作命令        命令查找机制:            查找内部命令   ...

  2. gulp connect.static is not a function

    npm install --save serve-static var serveStatic = require('serve-static');

  3. TF_RNNCell

    参考:链接. RNNCell BasicRNNCell GRUCell BasicLSTMCell LSTMCell MultiRNNCell 抽象类RNNCell 所有的rnncell均继承于RNN ...

  4. linux 计算机概论 Linux介绍

    CPU: CPU内部可以分为两个主要单元:算数逻辑单元和控制单元. 算数逻辑单元主要用于程序运算和逻辑判断,控制单元主要用于协调各个组件和各单元的工作. CPU基本可以分为两种: 精简指令集和复杂指令 ...

  5. 题解 POJ1149 Pigs

    先翻译一下吧(题面可以在原OJ上找) Mirko在一个由M个锁着的猪舍组成的养猪场工作,Mirko无法解锁任何猪舍,因为他没有钥匙.客户纷纷来到农场.他们每个人都有一些猪舍的钥匙,并想购买一定数量的猪 ...

  6. Java基础重点

    几个比较重要基础的,以后用到概率比较大的合集. 第一个,是获取时间以字符串形式输出的,用到了Date类.simpleDateFormat类的方法.贴图: 第二个是字符串转时间类型的,与上一个相似,不过 ...

  7. tomcat下载与安装

    https://www.cnblogs.com/limn/p/9358657.html

  8. HZOJ 20190727 T2 单(树上dp+乱搞?+乱推式子?+dfs?)

    考试T2,考试时想到了40pts解法,即对于求b数组,随便瞎搞一下就oxxk,求a的话,很明显的高斯消元,但考试时不会打+没开double挂成10pts(我真sb),感觉考试策略还是不够成熟,而且感觉 ...

  9. codevs 2291 糖果堆 x

                         题目描述 Description [Shadow 1]第一题 WJMZBMR买了很多糖果,分成了N堆,排成一列.WJMZBMR说,如果Shadow能迅速求出第 ...

  10. codevs 1013 求先序排列 2001年NOIP全国联赛普及组 x

                         题目描述 Description 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入描述 Inpu ...