..." to">..." to update what will be committed) (use "git checkout -- &_on branch mas">
当前位置:   article > 正文

git时空穿梭(版本回退)_on branch master changes not staged for commit: (u

on branch master changes not staged for commit: (use "git add ..." to

git管理的一些命令
修改read.txt文件为:

Git is a distributed version control system.
Git is free software.
  • 1
  • 2

命令git status可显示仓库当前状态

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   read.txt

no changes added to commit (use "git add" and/or "git commit -a")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

上面命令告诉我们read.txt被修改过,还没有提交
查看具体如何修改了git diff read.txt

index 99e0e11..013b5bc 100644
--- a/read.txt
+++ b/read.txt
@@ -1,2 +1,2 @@
 Git is a distributed version control system.
-Git is free software distributed under the GPL.
\ No newline at end of file
+Git is free software.
\ No newline at end of file

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

可以看到是第二行做了怎样的修改。
然后可以放心的把read.txt使用git addgit commit提交到仓库。

回到过去
每一个提交到仓库的版本叫做一个commit
命令git log可以显示从最近到最远的提交日志
在这里插入图片描述
可以看到这里有三个提交的版本
获得更精简的版本信息$ git log --pretty=oneline
在这里插入图片描述
前面一大串的字符为commit id版本号
现在要回到上一个版本使用命令git reset

$ git reset --hard head^
HEAD is now at 329c0f5 add distributed

  • 1
  • 2
  • 3

现在查看当前内容

$ cat read.txt
Git is a distributed version control system.
Git is free software.

  • 1
  • 2
  • 3
  • 4

内容被还原。
现在再使用git log查看版本信息
在这里插入图片描述
发现只有两个版本了,最新的版本看不到了。如果想再回到最新的版本办法也是有的:通过commit id版本号前几位还原。

$ git reset --hard a098
HEAD is now at a0982c2 append GPL

  • 1
  • 2
  • 3

注意:如果版本很多版本号前几位可能重复,尽量多打几位。

如果隔天想回到最新版本,命令git reflog记录了你每一次的操作,找到版本号如上进行还原。

总结:
1.git status查看仓库当前状态
2.假如有修改,git diff查看修改信息
3.git log查看版本信息 加--pretty=oneline参数可查看精简版本信息
4.git reflog查看命令历史,可用于回到最新版本
5.git reset切换版本 有两种使用方法
①按顺序:后加 head^回退一个版本head^^回退两个版本以此类推
②根据版本号:后加版本号前几位即可

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/264761?site
推荐阅读
相关标签
  

闽ICP备14008679号