修改git文件

修改本地库的文件,体验git版本与版本穿梭

初始化git目录 git init

1.1、创建一个文件,并提交到本地本地库

go 复制代码
echo "123" >  hello.txt		# 创建文件
git add hello.txt		# 加入到暂存区
git commit -m "first commit" hello.txt		# 提交到本地库
git relog		# 查看分支
复制代码
$ echo "123" > hello.txt
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git log
fatal: your current branch 'master' does not have any commits yet
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git commit -m "first commit" hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master (root-commit) 416f86e] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git log
commit 416f86eb3f1837f5ba07710ecb371a879e52c881 (HEAD -> master)		# 当前版本
Author: zhangsan <zhangsan@qq.com>	# 提交人
Date:   Fri Sep 1 10:52:37 2023 +0800		# 提交时间
    first commit			#  提交描述

1.2、修改工作区的文件并将文件提交到本地库

powershell 复制代码
echo "456" >> hello.txt
git add hello.txt	
git commit -m "second commit" hello.txt	
git relog		
复制代码
$ echo "456" >> hello.txt
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git commit -m "second commit" hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master cfcaa42] second commit
 1 file changed, 1 insertion(+)
Administrator@ecs-2145 MINGW64 /c/git-demo (master)
$ git log
commit cfcaa42d561d3375299763306c56bbd6614e0332 (HEAD -> master)		# 当前版本
Author: zhangsan <zhangsan@qq.com>
Date:   Fri Sep 1 11:05:10 2023 +0800
    second commit		
commit 416f86eb3f1837f5ba07710ecb371a879e52c881
Author: zhangsan <zhangsan@qq.com>
Date:   Fri Sep 1 10:52:37 2023 +0800
    first commit

1.3、版本穿梭,将版本回退至指定版本

git log #查看版本详细
git reflog #查看版本简略

powershell 复制代码
git log
复制代码
$ git  log
commit cfcaa42d561d3375299763306c56bbd6614e0332 (HEAD -> master)	# HEAD 指向即为当前版本
Author: zhangsan <zhangsan@qq.com>
Date:   Fri Sep 1 11:05:10 2023 +0800

    second commit

commit 416f86eb3f1837f5ba07710ecb371a879e52c881
Author: zhangsan <zhangsan@qq.com>
Date:   Fri Sep 1 10:52:37 2023 +0800

    first commit

1.3.1、版本切换至 416f86eb3f1837f5ba07710ecb371a879e52c881 这个版本

也可以使用版本前7位

复制代码
语法:git reset --hard 版本号

也可以使用 git checkout 版本号 来切换版本或者分支

powershell 复制代码
git reset --hard 416f86eb3f1837f5ba07710ecb371a879e52c881 
git log
复制代码
$ git reset --hard 416f86eb3f1837f5ba07710ecb371a879e52c881
HEAD is now at 416f86e first commit

$ git log
commit 416f86eb3f1837f5ba07710ecb371a879e52c881 (HEAD -> master)		# 当前所处版本
Author: zhangsan <zhangsan@qq.com>
Date:   Fri Sep 1 10:52:37 2023 +0800

    first commit

1.3.2、查看文件变化

powershell 复制代码
cat hello.txt
复制代码
$ cat hello.txt
123

可以发现之间写入的456已经没有了,回到了最初的时候

补充:

复制代码
可以打开.git\refs\heads\master查看版本号
相关推荐
qq_54702617925 分钟前
Git 使用指南
git
黄焖鸡能干四碗27 分钟前
智能制造工业大数据应用及探索方案(PPT文件)
大数据·运维·人工智能·制造·需求分析
世岩清上34 分钟前
乡村振兴主题展厅本土化材料运用与地域文化施工表达
大数据·人工智能·乡村振兴·展厅
说私域1 小时前
短视频私域流量池的变现路径创新:基于AI智能名片链动2+1模式S2B2C商城小程序的实践研究
大数据·人工智能·小程序
MM_MS1 小时前
Halcon图像锐化和图像增强、窗口的相关算子
大数据·图像处理·人工智能·opencv·算法·计算机视觉·视觉检测
XiaoHu02072 小时前
Linux多线程(详细全解)
linux·运维·服务器·开发语言·c++·git
焦耳热科技前沿2 小时前
中科大EMA:3秒焦耳热一步合成双功能催化剂用于甲醇氧化协同高效制氢
大数据·人工智能·自动化·能源·材料工程
向量引擎小橙2 小时前
推理革命与能耗:AI大模型应用落地的“冰山成本”与破局之路
大数据·人工智能·深度学习·集成学习
*才华有限公司*2 小时前
RTSP视频流播放系统
java·git·websocket·网络协议·信息与通信
一条咸鱼_SaltyFish3 小时前
[Day15] 若依框架二次开发改造记录:定制化之旅 contract-security-ruoyi
java·大数据·经验分享·分布式·微服务·架构·ai编程