修改git文件

这篇具有很好参考价值的文章主要介绍了修改git文件。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

初始化git目录 git init

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

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、修改工作区的文件并将文件提交到本地库

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 #查看版本简略

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 版本号 来切换版本或者分支

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、查看文件变化
cat hello.txt
$ cat hello.txt
123

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

补充:文章来源地址https://www.toymoban.com/news/detail-696403.html

可以打开.git\refs\heads\master查看版本号

到了这里,关于修改git文件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Git基本操作之 修改提交信息 取消暂存文件 撤销文件修改

    git 文件分为         本地文件【即你当前在git  bash终端ls 看到的文件】         暂存文件【即你使用了git  add 之后存储在index file 的文件,此文件是下一步commit的暂存】         仓库文件【即执行了git commit之后的文件】 1.修改提交信息 ,这里指的是修改 git  commit的时

    2023年04月08日
    浏览(43)
  • Git的基本操作(安装Git,创建本地仓库,配置Git,添加、修改、回退、撤销修改、删除文件)

    Git 是开放源代码的代码托管⼯具,最早是在Linux下开发的。开始也只能应⽤于Linux平台,后⾯慢慢的被移植到windows下,现在,Git可以在Linux、Unix、Mac和Windows这⼏⼤平台上正常运⾏了。 如果你的的平台是centos,安装git相当简单,以我的centos7.6为例: 我们还可以用下面的指令来

    2024年03月28日
    浏览(54)
  • 修改文件名后Git仓上面并没有修改

    场景: 我在本地将文件夹名称由Group → group ,执行git push 后,远程分支上的文件名称并没有修改。 原因: 是我绕过了git 直接使用了系统的重命名操作。 在 Git 中,对于已经存在的文件或文件夹进行大小写重命名是一个敏感的操作,因为在某些操作系统(如 Windows)中,文件

    2024年02月10日
    浏览(34)
  • git查看最近修改的文件

    git log --name-status 每次修改的文件列表, 显示状态 git log --name-only 每次修改的文件列表 git log --stat 每次修改的文件列表, 及文件修改的统计 git whatchanged 每次修改的文件列表 git whatchanged --stat 每次修改的文件列表, 及文件修改的统计 git show 显示最后一次的文件改变的具体内容

    2024年02月12日
    浏览(33)
  • Git—文件添加查看删除修改

    目录 1.添加文件—场景一 2.查看.git文件 3.添加文件—场景三 4.修改文件 5.版本回退 6.撤销修改 7.删除文件 在包含.git的目录下新建⼀个ReadMe文件,我们可以使用 git add 命令可以将文件添加到暂存 区: ●添加一个或多个文件到暂存区: git add [file1] [file2] ●添加指定目录到暂存

    2024年02月05日
    浏览(32)
  • Git - 如何将git修改的文件导出和导入

    1.应用场景 主要用于将git修改的文件导出和导入, 帮助提高工作效率。 2.学习/操作 来自chatGPT的对话 如果您只是想将 Git 仓库中的文件导出到本地磁盘中,而不需要保留 Git 的历史记录和元数据,可以使用 git archive 命令来实现。 git archive 命令可以将 Git 仓库中的指定文件或文

    2023年04月20日
    浏览(27)
  • git 检测不到修改了的文件

    概述 明明修改了了文件,但是 git 没检测到,执行 git status 发现没有修改的文件,可能有两种情况, 1. 修改了的文件没保存 手动保存文件后,再次执行 git status ,查看输出结果中是否出现刚才保存的文件。 这种情况大多发生在,更换了电脑或者重装了编译器,原来的编译器

    2024年02月11日
    浏览(40)
  • git 查看某次commit对应修改的文件

    如果不指定commit_id 默认展示最近一次commit修改的文件 如果 git log 也想看到每次commoit 修改的文件 diff 也能用这个参数

    2024年02月12日
    浏览(31)
  • 1.vscode修改文件,git没有显示变化

    在正常情况下修改文件或添加文件之后,文件夹会变颜色以提示文件被修改。但是偶然发现对文件做修改之后,vscode没有任何提示,也无法提交代码到git。原因是在项目最外层文件夹(项目名的同级目录下)git init了,产生了.git文件。 解决方法:在终端进入最外层(项目名所

    2024年02月13日
    浏览(28)
  • git把某一次commit修改过的文件打包导出(git)

    1、使用命令把修改的文件打包导出:打包某次commit: 2、使用命令把某次节点后的文件导出: window 下: 3、linux下:  

    2024年02月04日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包