git命令行操作
一. 创建存储库并设置签名
1.1 创建存储库
鼠标右键->Git gui here

选择 create new repository

创建完成后如下图:

通过Git gui打开 Git bash
注意:.git 目录中存放的是本地库相关的子目录和文件,不要删除,也不要胡
乱修改。

1.2 设置签名
-
形式:
用户名:zqs
Email 地址:test@abc.com -
作用:
区分不同开发人员的身份 -
辨析:
这里设置的签名和登录远程库(代码托管中心)的账号、密码没有任何关系。 -
命令:
4.1 项目级别/仓库级别:仅在当前本地库范围内有效
git config user.name zqs
git config user.email test@abc.com
信息保存位置:./.git/config 文件
image.png
4.2 系统用户级别:登录当前操作系统的用户范围
git config --global user.name zqs
git config --global user.email test@abc.com
信息保存位置:./.git/config 文件
- 级别优先级
就近原则:项目级别优先于系统用户级别,二者都有时采用项目级别
的签名
如果只有系统用户级别的签名,就以系统用户级别的签名为准
二者都没有不允许
二. 基本操作
在E:\Bigdata目录下创建一个test1.txt文件
git add test1.txt
2.1 状态查看
命令:
git status

2.2 添加
git add [filename]
将工作区的"新建/修改"添加到暂存区

2.3 提交
git commit -m "commit message" [file name]
将暂存区的内容提交到本地库

2.4 查看历史记录
git log

多屏显示控制方式:
空格向下翻页
b 向上翻页
q 退出
git log --pretty=oneline

git log --oneline

git reflog

2.5 前进后退
test1.txt里面已有数据 aaaa
再写入一行bbb
bbb
git add test1.txt
git commit -m "bbbb" test1.txt
再写入一行cccc
cccc
git add test1.txt
git commit -m "cccc" test1.txt
2.5.1 基于索引值操作[推荐]
语法:
git reset --hard [局部索引值]
命令:
cat test1.txt
git log --oneline
git reset --hard 0b3860b
git log --oneline
cat test1.txt
测试记录:

在测试一个前进的:

2.5.2 使用^符号:只能后退
git reset --hard HEAD^
注:一个^表示后退一步,n 个表示后退n 步
2.5.3 使用~符号:只能后退
git reset --hard HEAD~n
注:表示后退n 步
2.6 reset 命令的三个参数对比
2.6.1 --soft 参数
仅仅在本地库移动HEAD 指针

2.6.2 --mixed 参数
在本地库移动HEAD 指针
重置暂存区

2.6.3 --hard 参数
在本地库移动HEAD 指针
重置暂存区
重置工作区
2.7 删除文件并找回
前提:删除前,文件存在时的状态提交到了本地库。
操作:git reset --hard [指针位置]
- 删除操作已经提交到本地库:指针位置指向历史记录
- 删除操作尚未提交到本地库:指针位置使用HEAD
2.8 比较文件差异
git diff [文件名]
将工作区中的文件和暂存区进行比较
git diff [本地库中历史版本] [文件名]
将工作区中的文件和本地库历史记录比较
不带文件名比较多个文件