修改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查看版本号
相关推荐
T06205142 小时前
工具变量-5G试点城市DID数据(2014-2025年
大数据
向往鹰的翱翔2 小时前
BKY莱德因:5大黑科技逆转时光
大数据·人工智能·科技·生活·健康医疗
鸿乃江边鸟3 小时前
向量化和列式存储
大数据·sql·向量化
IT毕设梦工厂4 小时前
大数据毕业设计选题推荐-基于大数据的客户购物订单数据分析与可视化系统-Hadoop-Spark-数据可视化-BigData
大数据·hadoop·数据分析·spark·毕业设计·源码·bigdata
java水泥工4 小时前
基于Echarts+HTML5可视化数据大屏展示-白茶大数据溯源平台V2
大数据·echarts·html5
广州腾科助你拿下华为认证6 小时前
华为考试:HCIE数通考试难度分析
大数据·华为
在未来等你8 小时前
Elasticsearch面试精讲 Day 17:查询性能调优实践
大数据·分布式·elasticsearch·搜索引擎·面试
大数据CLUB11 小时前
基于spark的澳洲光伏发电站选址预测
大数据·hadoop·分布式·数据分析·spark·数据开发
ratbag67201311 小时前
当环保遇上大数据:生态环境大数据技术专业的课程侧重哪些领域?
大数据
计算机编程小央姐13 小时前
跟上大数据时代步伐:食物营养数据可视化分析系统技术前沿解析
大数据·hadoop·信息可视化·spark·django·课程设计·食物