git reflog 和 log 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17857723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between git reflog and log?
提问by Noich
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.
手册页说 log 显示提交日志,而 reflog 管理 reflog 信息。reflog 信息究竟是什么,它有哪些日志没有的信息?日志似乎要详细得多。
回答by ben_h
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.
git log
显示当前的 HEAD 及其祖先。也就是说,它打印 HEAD 指向的提交,然后是它的父级、它的父级等等。它通过递归查找每个提交的父项,遍历 repo 的祖先。
(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 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.
git reflog
根本不遍历 HEAD 的祖先。reflog 是 HEAD 指向的提交的有序列表:它是您的 repo 的撤消历史记录。reflog 不是 repo 本身的一部分(它与提交本身分开存储)并且不包含在推送、获取或克隆中;这纯粹是本地的。
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.
旁白:了解 reflog 意味着一旦提交,您就不会真正丢失 repo 中的数据。如果您不小心重置为较旧的提交,或错误地重新设置基准,或任何其他视觉上“删除”提交的操作,您可以使用 reflog 查看您之前所在的位置并git reset --hard
返回到该 ref 以恢复您以前的状态。请记住,refs 不仅意味着提交,还意味着其背后的整个历史。
回答by VonC
git log
shows the commit log accessible from the refs (heads, tags, remotes)git reflog
is a recordof all commits that are or were referenced in your repo at any time.
git log
显示可从 refs (heads, tags, remotes) 访问的提交日志git reflog
是任何时候在您的回购中引用或引用的所有提交的记录。
That is why git reflog
(a localrecording which is pruned after 90 days by default) is used when you do a "destructive" operation (like deleting a branch), in order to get back the SHA1 that was referenced by that branch.
See git config
:
这就是为什么当您执行“破坏性”操作(例如删除分支)时使用(默认情况下在 90 天后修剪git reflog
的本地记录),以取回该分支引用的 SHA1。
见git config
:
gc.reflogexpire
gc.<pattern>.reflogexpire
git reflog
expire removes reflog entries older than this time; defaults to 90 days.
With "<pattern>
" (e.g. "refs/stash
") in the middle the setting applies only to the refs that match the<pattern>
.
git reflog
expire 删除早于这个时间的 reflog 条目;默认为 90 天。中间
带有“<pattern>
”(例如“refs/stash
”)的设置仅适用于匹配<pattern>
.
git reflog
is often reference as "your safety net"
git reflog
通常被称为“您的安全网”
In case of trouble, the general advice, when git log doesn't show you what you are looking for, is:
万一出现问题,一般建议,当 git log 没有显示您正在寻找的内容时,是:
Again, reflog is a local recording of your SHA1.
As opposed to git log
: if you push your repo to an upstream repo, you will see the same git log
, but not necessarily the same git reflog
.
同样,reflog 是 SHA1 的本地记录。
与此相反git log
:如果您将存储库推送到上游存储库,您将看到相同的内容git log
,但不一定相同git reflog
。
回答by VonC
Here's the explanation of reflog
from the Pro Git book:
One of the things Git does in the background while you're working away is keep a reflog — a log of where your HEAD and branch references have been for the last few months.
You can see your reflog by using
git reflog
:$ git reflog 734713b... HEAD@{0}: commit: fixed refs handling, added gc auto, updated d921970... HEAD@{1}: merge phedders/rdocs: Merge made by recursive. 1c002dd... HEAD@{2}: commit: added some blame and merge stuff 1c36188... HEAD@{3}: rebase -i (squash): updating HEAD 95df984... HEAD@{4}: commit: # This is a combination of two commits. 1c36188... HEAD@{5}: rebase -i (squash): updating HEAD 7e05da5... HEAD@{6}: rebase -i (pick): updating HEAD
Every time your branch tip is updated for any reason, Git stores that information for you in this temporary history. And you can specify older commits with this data, as well.
当你在工作时,Git 在后台做的一件事就是保留一个 reflog——一个记录你的 HEAD 和分支引用在过去几个月里的位置的日志。
您可以使用
git reflog
以下命令查看您的 reflog :$ git reflog 734713b... HEAD@{0}: commit: fixed refs handling, added gc auto, updated d921970... HEAD@{1}: merge phedders/rdocs: Merge made by recursive. 1c002dd... HEAD@{2}: commit: added some blame and merge stuff 1c36188... HEAD@{3}: rebase -i (squash): updating HEAD 95df984... HEAD@{4}: commit: # This is a combination of two commits. 1c36188... HEAD@{5}: rebase -i (squash): updating HEAD 7e05da5... HEAD@{6}: rebase -i (pick): updating HEAD
每次您的分支提示因任何原因更新时,Git 都会在此临时历史记录中为您存储该信息。您也可以使用这些数据指定较旧的提交。
The reflog
command can also be used to delete entries or expire entries from the reflog that are too old. From the official Linux Kernel Git documentation for reflog
:
该reflog
命令还可用于从太旧的 reflog 中删除条目或使条目过期。来自官方 Linux 内核 Git 文档reflog
:
The subcommand
expire
is used to prune older reflog entries.To delete single entries from the reflog, use the subcommand
delete
and specify the exact entry (e.g.git reflog delete master@{2}
).
该子命令
expire
用于修剪较旧的 reflog 条目。要从引用日志中删除单个条目,请使用子命令
delete
并指定确切的条目(例如git reflog delete master@{2}
)。
回答by mitch
I was curious about this as well and just want to elaborate and summarize a bit:
我对此也很好奇,只想详细说明和总结一下:
git log
shows a history of all your commits for the branch you're on. Checkout a different branch and you'll see a different commit history. If you want to see you commit history for all branches, typegit log --all
.git reflog
shows a record of your references as Cupcake said. There is an entry each time a commit or a checkout it done. Try switching back and forth between two branches a few times usinggit checkout
and rungit reflog
after each checkout. You'll see the top entry being updated each time as a "checkout" entry. You do not see these types of entries ingit log
.
git log
显示您所在分支的所有提交的历史记录。签出不同的分支,您将看到不同的提交历史记录。如果要查看所有分支的提交历史记录,请键入git log --all
.git reflog
正如 Cupcake 所说,显示您的参考记录。每次提交或结帐时都会有一个条目。尝试在两个分支之间来回切换几次使用git checkout
并git reflog
在每次结帐后运行。您会看到每次都将顶部条目更新为“结帐”条目。您在 中看不到这些类型的条目git log
。
References: http://www.lornajane.net/posts/2014/git-log-all-branches
参考资料:http: //www.lornajane.net/posts/2014/git-log-all-branches
回答by user10028634
Actually, reflog is an alias for
实际上,reflog 是一个别名
git log -g --abbrev-commit --pretty=oneline
so the answer should be: it is a specific case.
所以答案应该是:这是一个特定的案例。