What's the difference between git reflog and log?

前端 未结 7 2037
名媛妹妹
名媛妹妹 2020-11-30 16:36

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 l

7条回答
  •  一个人的身影
    2020-11-30 17:31

    • 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:

    gc.reflogexpire
    gc..reflogexpire
    

    git reflog expire removes reflog entries older than this time; defaults to 90 days.
    With "" (e.g. "refs/stash") in the middle the setting applies only to the refs that match the .

    safety net

    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:

    "Keep calm and use git reflog"

    keep calm

    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.

提交回复
热议问题