What's the difference between git reflog and log?

前端 未结 7 2039
名媛妹妹
名媛妹妹 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 will start from current HEAD, that is point to some branch (like master) or directly to commit object (sha code), and will actually scan the object files inside .git/objects directory commit after commit using the parent field that exist inside each commit object.

    Experiment: point the HEAD directly to some commit: git checkout a721d (create new repo and populate it with commits and branches. replace a721d with some of your commit code) and delete the branches rm .git/refs/heads/* Now git log --oneline will show only HEAD and its commits ancestors.

    git reflog on the other hand is using direct log that is created inside .git/logs

    Experiment: rm -rf .git/logs and git reflog is empty.

    Anyway, even if you lose all tags and all branches and all logs inside logs folder, the commits objects are inside .git/objects directory so you can reconstruct the tree if you find all dangling commits: git fsck

提交回复
热议问题