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.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Here's the explanation of
reflog
from the Pro Git book: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 forreflog
:git log
shows the commit log accessible from the refs (heads, tags, remotes)git reflog
is a record of all commits that are or were referenced in your repo at any time.That is why
git reflog
(a local recording 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
:git reflog
is often reference as "your safety net"In case of trouble, the general advice, when git log doesn't show you what you are looking for, is:
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 samegit log
, but not necessarily the samegit reflog
.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
.References: http://www.lornajane.net/posts/2014/git-log-all-branches
Actually, reflog is an alias for
so the answer should be: it is a specific case.
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.