GIT03_初始化init、查看状态status、添加add、删除rm、commit提交、历史版本reflog、忽略文件gitignore(四)

简介: ⑧. 历史版本 reflog log⑨. Git工作目录下文件的两种状态⑩. .gitignore

⑧. 历史版本 reflog log


  • ①. 查看历史版本(git reflog 查看版本信息 | git log 查看版本详细信息)


$ git reflog
272a9cd (HEAD -> master) HEAD@{0}: commit (initial): 第一次提交 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git log
commit 272a9cde6cd70ec607687b6ce161fc46f8b9de2b (HEAD -> master)
Author: o-tangzhi <o-tangzhi@ghac.cn>
Date:   Sun May 16 17:10:35 2021 +0800
    第一次提交 a.txt


②. 版本穿梭(git reset --hard 版本号)

我们在a.txt最后添加了第二次版本


Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   a.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git add -A
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git commit -m "第二次提交了" a.txt
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory
[master c5d3d8a] 第二次提交了
 1 file changed, 1 insertion(+)
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git log
commit c5d3d8a380a444650db481f6ea2b84a0a0371716 (HEAD -> master)
Author: o-tangzhi <o-tangzhi@ghac.cn>
Date:   Sun May 16 17:16:19 2021 +0800
    第二次提交了
commit 272a9cde6cd70ec607687b6ce161fc46f8b9de2b
Author: o-tangzhi <o-tangzhi@ghac.cn>
Date:   Sun May 16 17:10:35 2021 +0800
    第一次提交 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git reflog
c5d3d8a (HEAD -> master) HEAD@{0}: commit: 第二次提交了
272a9cd HEAD@{1}: commit (initial): 第一次提交 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git reset --hard 272a9cd  # 注意这里切换到了第一次版本提交
HEAD is now at 272a9cd 第一次提交 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git reflog
272a9cd (HEAD -> master) HEAD@{0}: reset: moving to 272a9cd
c5d3d8a HEAD@{1}: commit: 第二次提交了
272a9cd (HEAD -> master) HEAD@{2}: commit (initial): 第一次提交 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
# 注意这里切换到第二次
$ git reset --hard c5d3d8a
HEAD is now at c5d3d8a 第二次提交了
$ cat a.txt
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
hello TANGZHI
第二次版本迭代


⑨. Git工作目录下文件的两种状态


  • ①. untracked 未跟踪(未被纳入版本控制)


  • ②. tracked 已跟(被纳入版本控制)
    Unmodified 未修改状态
    Modified 已修改状态
    Staged 已暂存状态
    这些文件的状态会随着我们执行Git的命令发生变化


⑩. .gitignore


  # no .a files :.a结尾的都要忽略
  *.a 
  # !lib.a 不需要忽略
  !lib.a 
  # /TODO的这个文件需要忽略
  /TODO 
  # build目录下所有的文件都忽略
  build/ 
  # doc目录下以.txt文件的都要忽略
  doc/*.txt 
  # doc目录下所有或子目录下所有的.pdf文件都要忽略
  doc/**/*.pdf
相关文章
|
12月前
|
开发工具 git
使用Git根据日期进行代码版本切换的方法
通过以上步骤,可以有效地根据日期进行Git代码版本的切换。这种方法在需要回溯历史版本进行bug修复或功能复查时特别有用。Git的灵活性和强大功能使其成为现代软件开发不可或缺的工具之一。
1060 103
|
安全 开发工具 git
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
960 5
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
|
存储 人工智能 缓存
Git Commit规范:为什么有些公司要求变更行数限制?·优雅草卓伊凡
Git Commit规范:为什么有些公司要求变更行数限制?·优雅草卓伊凡
619 3
Git Commit规范:为什么有些公司要求变更行数限制?·优雅草卓伊凡
|
API 开发工具 git
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
836 0
使用git pull遇到Automatic merge failed; fix conflicts and then commit the result.解决方案卓伊凡
|
开发工具 git
使用Git下载指定版本或指定commit
使用Git下载指定版本或指定commit
|
JavaScript 前端开发 持续交付
实际工作中 Git Commit 代码提交规范是什么样的?
实际工作中 Git Commit 代码提交规范是什么样的?
1331 7
|
Linux 开发工具 数据安全/隐私保护
分布式版本控制git
分布式版本控制git
|
存储 缓存 数据处理
71_数据版本控制:Git与DVC在LLM开发中的最佳实践
在2025年的大模型(LLM)开发实践中,数据和模型的版本控制已成为确保项目可重复性和团队协作效率的关键环节。与传统软件开发不同,LLM项目面临着独特的数据版本控制挑战:
1140 0
|
敏捷开发 存储 开发工具
版本控制系统的选择:Git与SVN的比较
【8月更文挑战第14天】Git和SVN都是优秀的版本控制系统,它们各自具有独特的优势和适用场景。在选择版本控制系统时,需要根据具体的项目需求、团队特点和开发模式来综合考量。对于需要分布式团队协作、高效处理大型项目或采用敏捷开发模式的团队来说,Git是一个更好的选择。而对于传统团队、集中式开发或简单项目来说,SVN可能更加合适。无论选择哪种版本控制系统,都应该充分利用其提供的工具和功能来提高代码质量和开发效率。
1022 6
|
项目管理 开发工具 git
版本控制与源代码管理:在 Visual Basic 项目中使用 Git
【4月更文挑战第27天】本文介绍了在Visual Basic项目中使用Git进行版本控制和源代码管理的重要性。Git作为一个流行的分布式版本控制系统,具备分布式架构、高效性能和强大分支管理等特点。在项目中,需先安装Git,然后初始化仓库、添加文件和提交更改。常用操作包括查看状态、日志、创建及切换分支和合并分支。团队协作时,借助远程仓库和推送拉取命令实现代码共享。虽然Git有学习曲线,但其优势在于强大的功能、灵活性和社区支持,能提升开发效率和代码质量。通过学习和实践,开发者可充分利用Git优化协作和项目管理。
398 1