Git-第二篇廖雪峰Git教程学习笔记(1)基本命令,版本回退
1、安装Git-2.16.2-64-bit.exe后,设置用户名,用户邮箱
#--global参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

2、创建版本库
命令:git init
版本库:版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改、删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可以“还原”。

3、把文件添加到版本库
命令:git add 文件
解析:将文件添加到暂存区

命令:git commit -m "log description"
解析:将文件添加到本地库。-m命令用于添加提交说明日志。

命令:git status
解析:查看当前的文件修改状态。上面截图因为我们已经提交到本地仓库了,所以当前库中没有任何修改。
命令:git diff 文件
解析:查看指定文件差异。
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ 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: readme.txt no changes added to commit (use "git add" and/or "git commit -a") lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git diff readme.txt
warning: LF will be replaced by CRLF in readme.txt.
The file will have its original line endings in your working directory.
diff --git a/readme.txt b/readme.txt
index 9c69c9c..4b1c78e
--- a/readme.txt
+++ b/readme.txt
@@ -, +, @@
-GIt is a version control system.
+GIt is a distributed version control system.
Git is free software. lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$
4、版本回退
命令:git log [--pretty=oneline]
解析:显示从最近到最远的提交日志
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git log
commit adde96d057448c792343465df3aee108764defbd (HEAD -> master)
Author: lfy <@qq.com>
Date: Sat Aug :: + add GPL commit 31728b8d6ec5a40ed7eca72aca63533d8625b423
Author: lfy <@qq.com>
Date: Sat Aug :: + add distributed commit 586474b5bd16e377df3b657ffc1b35f663a69038
Author: lfy <@qq.com>
Date: Sat Aug :: + create readme.txt
在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
现在,我们要把当前版本append GPL回退到上一个版本add distributed,就可以使用git reset命令
命令:git reset --hard commit_id
解析:
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git reset --hard HEAD^
HEAD is now at 31728b8 add distributed
再次查看log,发现我们最后一次提交的内容已经找不到了。但是,只要当前窗口没有关闭(或者关闭了但你要记得commit id),还是可以再找回的,要输入之前查看的commit id。(即adde96d057...)
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git log
commit 31728b8d6ec5a40ed7eca72aca63533d8625b423 (HEAD -> master)
Author: lfy <@qq.com>
Date: Sat Aug :: + add distributed commit 586474b5bd16e377df3b657ffc1b35f663a69038
Author: lfy <@qq.com>
Date: Sat Aug :: + create readme.txt lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git reset --hard adde96
HEAD is now at adde96d add GPL lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ cat readme.txt
GIt is a distributed version control system.
Git is free software distributed under the GPL. lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git log
commit adde96d057448c792343465df3aee108764defbd (HEAD -> master)
Author: lfy <1220429263@qq.com>
Date: Sat Aug 24 21:08:03 2019 +0800 add GPL commit 31728b8d6ec5a40ed7eca72aca63533d8625b423
Author: lfy <@qq.com>
Date: Sat Aug :: + add distributed commit 586474b5bd16e377df3b657ffc1b35f663a69038
Author: lfy <@qq.com>
Date: Sat Aug :: + create readme.txt lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$
命令:git reflog
解析:记录你的命令
lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$ git reflog
adde96d (HEAD -> master) HEAD@{}: reset: moving to adde96
31728b8 HEAD@{}: reset: moving to HEAD^
adde96d (HEAD -> master) HEAD@{}: commit: add GPL
31728b8 HEAD@{}: commit: add distributed
586474b HEAD@{}: commit (initial): create readme.txt lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
$
Git-第二篇廖雪峰Git教程学习笔记(1)基本命令,版本回退的更多相关文章
- Git-第四篇廖雪峰Git教程学习笔记(3)远程仓库,克隆远端库
1.本次连接的是gitHub仓库. 1>创建SSH Key. ssh-keygen -t rsa -C "youremail@example.com" lfy@lfy-PC ...
- Git-第三篇廖雪峰Git教程学习笔记(2)回退修改,恢复文件
1.工作区 C:\fyliu\lfyTemp\gitLocalRepository\yangjie 2.版本库 我们使用git init命令创建的.git就是我们的版本库.Git的版本库里存了很多东西 ...
- Git-第五篇廖雪峰Git教程学习笔记(4)分支
1.一开始,只有一个主分支(master),HEAD指向Master,而Master指向主分支.现在我们创建dev分支. lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/git ...
- 【python】廖雪峰python教程学习--基础
No1: 目前,Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的 No2: 用r''表示''内部的字符串默认不转义 No3: 以'''开头,敲回车可以换行 No4: 布尔 ...
- git-廖雪峰版教程学习笔记
- 【学习总结】Git学习-参考廖雪峰老师教程-总
公元2018-10-21 实验室台式机 win7 64位 参考教程: 廖雪峰Git教程 其他资料:Git-book 北大一只总结的笔记,最终整理的时候可以参考:Git笔记 评论区看到的另一个人,总结在 ...
- 廖雪峰 Git 教程 + Git-Cheat-Sheet 学习总结
廖雪峰 Git 教程 + Git-Cheat-Sheet 学习总结 本教程主要是个人的 Git 学习总结. 主要参考博客: 廖雪峰 Git 教程 Git-Cheat-Sheet 文章目录 廖雪峰 Gi ...
- 廖雪峰Git入门教程
廖雪峰Git入门教程 2018-05-24 23:05:11 0 0 0 https://www.liaoxuefeng.com/wiki/00137395163059296 ...
- 从零开始使用git第二篇:git的日常操作
从零开始使用git 第二篇:git的日常操作 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:git撤销操作.分支操 ...
随机推荐
- 八、ARM 汇编程序格式和程序控制
8.1 汇编程序格式 源程序中的语句可以分为两种类型:指令性语句.指示性语句 指示性语句就是一些伪操作,在 MDK 编译环境下的伪操作有下面几种: 符号定义伪操作 数据定义伪操作 汇编控制伪操作 其他 ...
- STM32 JTAG接口SWD下载接线图
- nacos 动态刷新@ConfigurationProperties
使用@ConfigurationProperties 可以替换@value @ConfigurationProperties @Value 注解功能 可以批量注入配置文件中的属性 只能一个个指定注 ...
- MyEclipse使用教程:使用Workbench和Perspectives
[MyEclipse CI 2019.4.0安装包下载] workbench指的是加载IDE时看到的内容,它通常包含一个perspective,这是相关视图和编辑器的布局.您可以根据正在进行开发的类型 ...
- MVC模式 和 MVVM模式
MVC模式 模型 - 视图 - 控制器或MVC,MVC是普遍的叫法,是一种软件设计模式,用于开发Web应用程序.模型- 视图 - 控制器模式是由以下三部分组成: 模型/Model - 一个负责维护数据 ...
- 【leetcode】1170. Compare Strings by Frequency of the Smallest Character
题目如下: Let's define a function f(s) over a non-empty string s, which calculates the frequency of the ...
- [luogu]P2680 运输计划[二分答案][树上差分]
[luogu]P2680 [NOIP2015]运输计划 题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n ...
- nginx 缓存设置
浏览器缓存原理 浏览器缓存 HTTP协议定义的缓存机制(如:Expires:Cache-control等) 2.浏览器无缓存 3.客户端有缓存 校验过期机制 校验是否过期 ...
- Miniprofiler在目中使用报 mini-profiler-resources/includes.js 404错误
原因,没有配置webconfig <system.webServer> <modules> <remove name="FormsAuthentication& ...
- jsoncpp 源码编译与简单使用
******************************************************标准C++实现jsoncpp 源码使用编译(VC2012 MFC)(Qt5.2 Widget ...