git stash - .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 会重复引用?

原木 对引用所做的更改的记录存储在此目录中。有关更多信息,请参阅 git-update-ref1。如果设置了 $GIT_COMMON_DIR 并改用"$GIT_COMMON_DIR/logs",则忽略此目录。

参考:gitrepository-layout

它们是"reflogs",记录了存储库中各种引用过去指向的历史记录。

请参阅git help reflog和文档以了解git help log中的-g, --walk-reflogs

如果您运行了diff -r则会看到更多差异,因为refs/文件都包含一个提交,并且logs/refs包含一个历史记录文件。

请注意,查找refs/目录通常不是在存储库中查找 ref 的好方法。除了"松散"之外,refs 也可能只存在于packed-refs中,而在 refs/ 目录中没有相应的条目。

logs 目录是 Git 存储 reflog 的地方。参考日志指示您的参考文献在较早的时间点指向的内容。Reflogs 即使在git commit --amendgit rebase等之后也会存储原始提交。Reflogs 即使在git pull拉入数十次提交后也会存储单个提交。引用日志可以轻松撤消某些操作。

对于您拥有的所有

引用以及您最近拥有的所有引用,都存在 reflog 是正常的。您有时通过使用 git stash 命令获得了stash引用。即使您现在不再拥有该引用,引用日志也会记住。例如,这使您可以撤消意外的分支删除。

最新更新