git reflog和log有什么区别? [英] What's the difference between git reflog and log?

查看:187
本文介绍了git reflog和log有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

手册页说日志显示提交日志,并且reflog管理reflog信息。什么是reflog信息,它有什么,日志没有?日志似乎更加详细。

解决方案

git log HEAD及其祖先。也就是说,它将打印提交HEAD点,然后打印其父,父,等等。它通过回购的祖先遍历,通过递归地查找每个提交的父项。



(实际上,一些提交有多个父代。代表性日志,使用像 git log --oneline --graph --decorate 这样的命令。)



git reflog 根本不会遍历HEAD的血统。 reflog是HEAD指出的提交的有序列表:它是您的回购的撤消历史记录。 reflog不是repo本身的一部分(它被单独存储到提交本身),并且不包含在推送,提取或克隆中;它是纯粹的本地的。



另外:理解reflog意味着一旦它被提交,你不能真的从你的repo中丢失数据。如果您不小心重置为较旧的提交或错误地重新绑定,或者任何其他视觉上移除提交的操作,那么您可以使用reflog来查看以前的位置,并且 git reset --hard 回到那个参考文件来恢复你以前的状态。记住,参考文献不仅意味着承诺,还包括它背后的整个历史。


The man page says that log shows the commit logs and reflog manages reflog information. What exactly is reflog information and what does it have that the log doesn't? The log seems far more detailed.

解决方案

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) and isn't included in pushes, fetches or clones; it's purely local.

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 the reflog to see where you were before and git reset --hard back to that ref to restore your previous state. Remember, refs imply not just the commit but the entire history behind it.

这篇关于git reflog和log有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆