Git:git-reflog的⽤法总结
原帖收藏于,传递⼀个IT⽼兵在凋零前的光和氧。
git-reflog的⽤法总结。
前⾔
git-reflog是⽤来恢复本地错误操作很重要的⼀个命令,所以在这⾥对它进⾏⼀下整理。
正⽂
概要
管理reflog信息。
语法
git reflog <subcommand> <options>
具体的⽤法
git reflog [show] [log-options] [<ref>]
git reflog expire [--expire=<time>] [--expire-unreachable=<time>] [--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] [--verbose] [--all | <refs>…]
git reflog delete [--rewrite] [--updateref] [--dry-run | -n] [--verbose] ref@{specifier}…exists的用法
git reflog exists <ref>
Reference logs, or “reflogs”, record when the tips of branches and other references were updated in the local repository.
这句话怎么理解呢,记录了“when”,时间?
翻译:Reference logs(参考⽇志),或者叫做”reflogs”,记录了分⽀的tips(提⽰信息?)或者其他参考在本地仓库被更新的时间(when)。
问题来了,这个参考⽇志的作⽤是什么,和⽇志⼜有什么区别呢?
到了这篇:
git log shows the current HEAD and its ancestry. That is, it prints the commit HEAD points to, then its parent, its parent, and so on. It traverses back through the repo's ancestry, by recursively looking up each commit's parent.
(In practice, some commits have more than one parent. To see a more representative log, use a command like git log --oneline --graph --decorate.)
git reflog doesn't traverse HEAD's ancestry at all. The reflog is an ordered list of the commits that HEAD has pointed to: it's undo history for your repo. The reflog isn't part of the repo itself (it's stored separately to the commits themselves) Aside: understanding the reflog means you can't really lose data from your repo once it's been committed. If you accidentally reset to an older commit, or rebase wrongly, or any other operation that visually "removes" commits, you can use 上⾯就讲的⽐较清楚了,总结⼀下:
git log是显⽰当前的HEAD和它的祖先的,递归是沿着当前指针的⽗亲,⽗亲的⽗亲,……,这样的原则。
git reflog根本不遍历HEAD的祖先。它是HEAD所指向的⼀个顺序的提交列表:它的undo历史。reflog并不是repo(仓库)的⼀部分,它单独存储,⽽且不包含在pushes,fetches或
者clones⾥⾯,它纯属是本地的。
reflog可以很好地帮助你恢复你误操作的数据,例如你错误地reset了⼀个旧的提交,或者rebase,……,这个时候你可以使⽤reflog去查看在误操作之前的信息,并且使⽤git reset --hard
去恢复之前的状态。
下⾯研究⼀下这个命令的具体⽤法。
先了解⼀下git的版本表⽰⽅法:
HEAD@{2} means “where HEAD used to be two moves ago”, master@{one.week.ago}means “where master used to point to one week ago in this local repository”
HEAD@{2}表⽰HEAD指针在两次移动之前的情况;⽽master@{one.week.ago}表⽰master在本地仓库⼀周之前的情况。
“show”⼦命令显⽰所指定的参考的⽇志。
实例:显⽰HEAD的reflog。
$ git reflog show
ef64f10 (HEAD -> BlueLake_theme) HEAD@{0}: commit: 新增ethereum-programming-intr oduction
122e0ec (origin/BlueLake_theme) HEAD@{1}: commit: 移除了冗余的ethereum-rationale ⽂章
c17fbbb HEAD@{2}: commit: 新增git-change-server-password⽂章
1603d1a HEAD@{3}: pull: Merge made by the 'recursive' strategy.
0ce1e93 HEAD@{4}: commit: 新增了以太坊原理
c73503c HEAD@{5}: commit: 修改了-X-Frame-Options的关键字
6af02f6 HEAD@{6}: commit: 新增了git-tag的⽂章;修改了git其他的⽂章,规范了名字、关键字
9087fbd HEAD@{7}: commit: 新增了gti-reset⽂章
039d95c HEAD@{8}: commit: 移除了没⽤的⽬录
ff72601 HEAD@{9}: commit: 修改成了next主题
ef64f10 (HEAD -> BlueLake_theme) HEAD@{0}: commit: 新增ethereum-programming-intr oduction
从上图可以看到,⼏乎所有的操作都记录在其中,这个就像MySQL,随时可以回滚。
“expire”⼦命令会删除掉更⽼的reflog条⽬。
“delete”⼦命令从reflog中删除⼀个条⽬。
“exists”⼦命令检查⼀个ref是否有⼀个reflog。
这⼏个命令就相对⽐较简单了,以后再尝试了。
参考
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论