【问题标题】:git --all missing commitgit --all 缺少提交
【发布时间】:2013-03-03 19:18:39
【问题描述】:

有人可以帮我理解这里发生了什么吗?

我从git log --oneline 开始,它吐出:

4df9421 (HEAD, master) moved some aliases around
d3810e4 (origin/master) some terminal color changes
a7182d3 git colors, ignores, etc.
995fe8c added gitconfig, moved some personal stuff out of the public repo
8a100b7 misc unimportant updates
55d2c08 added a fix to "open with", refactored
7ec7d83 Removed some vim colors; added a couple searching aliases
330c7fc Minor updates
44e80a1 Added vim files
48537c6 Fixed some formatting problems
14933a2 Initial Commit

然后我执行git reset --hard 330c7fc 将日志返回到:

330c7fc (HEAD, master) Minor updates
44e80a1 Added vim files
48537c6 Fixed some formatting problems
14933a2 Initial Commit

到目前为止一切顺利,但是(现在我已经重置)当我做git log --oneline --all 时,我得到:

 d3810e4 (origin/master) some terminal color changes
 a7182d3 git colors, ignores, etc.
 995fe8c added gitconfig, moved some personal stuff out of the public repo
 8a100b7 misc unimportant updates
 55d2c08 added a fix to "open with", refactored
 7ec7d83 Removed some vim colors; added a couple searching aliases
 330c7fc (HEAD, master) Minor updates
 44e80a1 Added vim files
 48537c6 Fixed some formatting problems
 14933a2 Initial Commit

请注意,此列表中缺少最新条目“4df9421 移动了一些别名”。

我的理解是--all 选项应该显示所有提交。为什么在我恢复到较早的提交后会丢失最新的?

谢谢。

【问题讨论】:

    标签: git


    【解决方案1】:

    它丢失了,因为它不再被 HEAD 或分支引用。
    您已使用 git reset --hard 将(HEAD 和 master)都重置为另一个提交。

    只有 git reflog 会显示最近的提交。

    git log --all 仅用于列出在refs/ 中引用的提交(如标签、头等)

    --all
    

    假装refs/ 中的所有引用都在命令行中列为<commit>

    【讨论】:

    • 知道了。这就说得通了。我想建议始终将您的一个分支保留在最近的提交上,如果您想恢复到更早的内容,请在分支中进行。
    • @OliverTaylor 是的:这样,您可以保留旧 HEAD 上的引用,然后在 git log --all 中仍然可见。
    • 这提出了一个问题,有没有办法将 reflog 中的提交与 log 中的提交结合起来?因此,无论它们是否存在于 refs/ 中,都会创建一个所有提交的主列表
    • @OliverTaylor 这通常是不可取的,以避免在例如 rebase 之后取消引用的类似提交所留下的所有污染(您会获得 2 组相同的提交)。话虽如此,请查看git log--walk-reflogs 选项。 (如stackoverflow.com/a/746790/6309
    【解决方案2】:

    --all 选项告诉git log 显示所有提交。它要求所有 refs 的日志,基本上是您的分支和标签。重置命令从master 中删除了该提交,这是包含它的唯一引用,因此现在无法访问该提交。

    【讨论】:

      【解决方案3】:

      您应该接受VonC's answer。完成它:

      “丢失的提交”未推送到服务器,或保存在另一个分支中。你的git reset --hard因此删除了它。

      幸运的是,git 有某种神奇的撤销堆栈:git reflog。查看 VonC 的链接以了解如何取回它。

      使用git reset时要小心,这个命令会破坏提交。

      根据经验:在您操纵历史记录之前,请确保您仍有办法回到原来的位置。我的本地存储库被 backuporigwip 分支破坏了,我每个月左右都会清理这些分支。

      【讨论】:

      • “删除它”?不完全是。它“取消引用它”。除非您执行 git gc --prune=today --aggressive(或 git gc --prune=now),否则它仍会列在 reflog 中(默认情况下为接下来的 90 天)。
      • 你当然是对的。如果有的话,否则您将无法恢复它。然而,在“正常的 git 流”中,看起来你真的已经删除了你的提交。
      猜你喜欢
      • 2016-10-03
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 2017-09-03
      相关资源
      最近更新 更多