.git/log 的目的是什么
What is the purpose of .git/log
我在搜索 git 保存隐藏提交的位置时注意到 .git/log
。发现:
$ ls .git/logs/
HEAD refs
$ diff .git/refs/ .git/logs/refs/ | head -n3
Common subdirectories: .git/refs/heads and .git/logs/refs/heads
Common subdirectories: .git/refs/remotes and .git/logs/refs/remotes
diff .git/refs/stash .git/logs/refs/stash
含义stash
- 是logs
下唯一的唯一文件。但它并没有阐明这个文件夹的基本原理。那么 .git/log
的目的是什么以及为什么 git 重复引用?
它们是 "reflogs",它记录了您存储库中各种引用过去指向的位置的历史记录。
参见git help reflog
and the documentation for -g, --walk-reflogs
in git help log
。
如果您有 运行 diff -r
,您会看到更多差异,因为 refs/
文件都包含一个提交,而 logs/refs
包含一个历史文件。
请注意,查找 refs/
目录通常不是在您的存储库中查找引用的好方法。除了 "loose" 之外,refs 也可能仅存在于 packed-refs
中,而在 refs/
目录中没有相应的条目。
logs
目录是 Git 存储 reflogs 的地方。引用日志指示您的引用在较早的某个时间点指向的内容。即使在 git commit --amend
、git rebase
等之后,Reflog 也会存储原始提交。即使在 git pull
拉入数十个提交后,Reflog 也会存储单个提交。 Reflog 可以轻松撤消某些操作。
对于您拥有的所有引用以及您最近拥有的所有引用,存在引用日志是正常的。通过使用 git stash
命令,您曾经有过 stash
ref。即使您现在不再拥有该 ref,reflog 也会记住。例如,这也可以让您撤消意外删除的分支。
logs
Records of changes made to refs are stored in this directory. See git-update-ref1 for more information. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/logs" will be used instead.
我在搜索 git 保存隐藏提交的位置时注意到 .git/log
。发现:
$ ls .git/logs/
HEAD refs
$ diff .git/refs/ .git/logs/refs/ | head -n3
Common subdirectories: .git/refs/heads and .git/logs/refs/heads
Common subdirectories: .git/refs/remotes and .git/logs/refs/remotes
diff .git/refs/stash .git/logs/refs/stash
含义stash
- 是logs
下唯一的唯一文件。但它并没有阐明这个文件夹的基本原理。那么 .git/log
的目的是什么以及为什么 git 重复引用?
它们是 "reflogs",它记录了您存储库中各种引用过去指向的位置的历史记录。
参见git help reflog
and the documentation for -g, --walk-reflogs
in git help log
。
如果您有 运行 diff -r
,您会看到更多差异,因为 refs/
文件都包含一个提交,而 logs/refs
包含一个历史文件。
请注意,查找 refs/
目录通常不是在您的存储库中查找引用的好方法。除了 "loose" 之外,refs 也可能仅存在于 packed-refs
中,而在 refs/
目录中没有相应的条目。
logs
目录是 Git 存储 reflogs 的地方。引用日志指示您的引用在较早的某个时间点指向的内容。即使在 git commit --amend
、git rebase
等之后,Reflog 也会存储原始提交。即使在 git pull
拉入数十个提交后,Reflog 也会存储单个提交。 Reflog 可以轻松撤消某些操作。
对于您拥有的所有引用以及您最近拥有的所有引用,存在引用日志是正常的。通过使用 git stash
命令,您曾经有过 stash
ref。即使您现在不再拥有该 ref,reflog 也会记住。例如,这也可以让您撤消意外删除的分支。
logs Records of changes made to refs are stored in this directory. See git-update-ref1 for more information. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/logs" will be used instead.