获取所有 Git 提交的列表,包括“丢失”的提交那些
假设我有一个像这样的图表:
A---B---C---D (master)
\
\-E---F (HEAD)
如果我执行 git log --all --oneline ,我将获得所有六个提交。
但如果图表是:
A---B---C---D (master, HEAD)
\
\-E---F
我将看不到 E 和 F。我可以让 Git 告诉我所有提交,包括那些未命名的分支上的提交吗?
Let's say that I have a graph like this:
A---B---C---D (master)
\
\-E---F (HEAD)
If I do git log --all --oneline
, I will get all six of my commits.
But if the graph is:
A---B---C---D (master, HEAD)
\
\-E---F
I will not see E and F. Can I get Git to tell me all the commits, including those on branches which are not named?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
尝试:
通过假装 reflogs (
git reflog
) 提到的所有对象都在命令行上列为
来列出所有 git 提交。Try:
which lists all git commits by pretending that all objects mentioned by reflogs (
git reflog
) are listed on the command line as<commit>
.拯救我生命的是下面的命令:
你会发现一个屏幕,其中有对 git 的历史提交,如下所示:
< img src="https://i.sstatic.net/Bkh4L.png" alt="在此处输入图片描述">
此时,只需找到
HEAD@{X}< /code> 您需要的,创建一个临时分支并像这样移动到它:
这样您将拥有一个包含丢失提交的临时分支,而无需重新设置或破坏更多 git 存储库。
希望这有帮助...
What saved my life was the following command:
There you find a screen with history commits done to git like this one:
At this point, you only have to find the
HEAD@{X}
that you need, create a temporary branch and move to it like this:That way you will have a temporary branch with your lost commit without rebasing or breaking even more your git repository.
Hope this helps...
不是特别容易——如果你失去了指向树枝尖端的指针,那就就像大海捞针一样。您可以找到所有似乎不再被引用的提交 - git fsck --unreachable 将为您执行此操作 - 但这将包括您在 git 之后丢弃的提交commit --amend,您重新建立基础的分支上的旧提交等等。因此,立即查看所有这些提交很可能需要费力地浏览太多信息。
所以轻率的答案是,不要忘记你感兴趣的事情。更严重的是,默认情况下,引用日志将保存对你在过去 60 天左右使用过的所有提交的引用。更重要的是,他们将提供一些关于这些提交的背景信息。。
Not particularly easily- if you've lost the pointer to the tip of a branch, it's rather like finding a needle in a haystack. You can find all the commits that don't appear to be referenced any more-
git fsck --unreachable
will do this for you- but that will include commits that you threw away after agit commit --amend
, old commits on branches that you rebased etc etc. So seeing all these commits at once is quite likely far too much information to wade through.So the flippant answer is, don't lose track of things you're interested in. More seriously, the reflogs will hold references to all the commits you've used for the last 60 days or so by default. More importantly, they will give some context about what those commits are.
当我解决这个问题时,我使用以下命令:
这让我可以可视化最近已变成无头的提交。
我将其封装在名为
~/bin/git-reflog-gitk
的脚本助手中。编辑: - 我的 git-reflog-gitk 包装器是多余的 - 因为你现在可以直接调用 gitk --reflog
When I tackle this issue I use the following command:
This lets me visualise recent commits which have become headless.
I have this wrapped up in a script helper called
~/bin/git-reflog-gitk
.Edit: - my git-reflog-gitk wrapper is redundant - as you can now call
gitk --reflog
directly就像 @Kieran 的答案,但对于控制台:
<代码>
git log --oneline --all --graph --decorate $(git reflog | awk '{print $1}')
Like @Kieran 's Answer, but for the console:
git log --oneline --all --graph --decorate $(git reflog | awk '{print $1}')
救了我!我在合并 HEAD 时丢失了我的,并且找不到我最近的提交!未显示在源代码树中,但 git log --reflog 显示了我之前的所有本地提交
saved me! I lost mine while merging HEAD and could not find my lates commit! Not showing in source tree but
git log --reflog
show all my local commits before我如何解决这个问题?使用 git fsck 和日志记录!
首先创建一个包含丢失(无法访问)的提交和 blob 的文件。 (注意:如果你做了像 git gc 这样的事情,那么它会垃圾收集所有提交的内容,并且你不会在这里找到它们!)
这会给你一个像这样的文件:
然后,您可以使用您喜欢的文本编辑器打开此文件,从那里复制提交/博客哈希值。 (*咳嗽* vim 宏非常适合这个*咳嗽*)
现在您可以使用
git log --oneline
。或者,gitk、tig 或任何其他 git 查看器也应该可以工作。
在您的情况下,如果您找到提交 F 的哈希值,日志将向您显示类似这样的内容,
快速而简单!现在您可以找到所有这些悬而未决的提交背后的上下文。
PS 是的,我知道,发帖晚了,但是哦,好吧,有人可能会在这里找到它并发现它有用。 (很可能是 6 个月后我再次用 google 搜索这个)
How I solve this problem? Use
git fsck
and logging!First create a file containing lost (unreachable) commits and blobs. (NOTE: if you did something like
git gc
then it will garbage collect all of they commits and you won't find them here!)That gives you a file like this:
You can then open this file with you favorite text editor to copy the commit/blog hashes from there. (*cough* vim macros works great for this *cough*)
Now you can log back from this commit with something like
git log --oneline <commit hash>
.Alternatively, gitk, tig, or any other git viewer should work.
In your case if you find the hash for commit F the log will show you something like this,
Quick and easy! Now you can find the context behind all of those dangling commits.
P.S. Yes, I know, late post, but oh well, somebody might find it here and find it useful. (Mostly likely me in 6 months when I google this again)
我很幸运地通过查看位于
.git/logs/HEAD
的引用日志来恢复提交,然后我不得不向下滚动到文件末尾 ,我找到了我刚刚丢失的提交。
I've had luck recovering the commit by looking at the reflog, which was located at
.git/logs/HEAD
I then had to scoll down to the end of the file, and I found the commit I just lost.
实际上 git fsck 可以用来查找所有丢失的提交,你只需要正确的选项:
--unreachable 单独是不够的,因为某些提交可能仍然被引用重新记录。如果您需要非常清晰地查看整个提交历史记录,您可以为类似的内容创建一个别名:
说实话,我不确定在最后一个命令中您是否需要
--unreachable
选项,鉴于git log
默认情况下遍历祖先(除非指定--no-walk
)。我不会打赌,但我认为没有必要。Actually
git fsck
can be used to find all the lost commits, you just need the right option:--unreachable
alone is not enough because some commits might still be referenced by the reflog. If you need a pretty clear view of the entire commit history, you can create an alias for something like this:To be honest I am not sure if in this last command you need the
--unreachable
option, given thatgit log
traverse the ancestors by default (unless--no-walk
is specified). I would not bet on it, but I think it is not necessary.我们有时无法通过 git log 获取所有提交详细信息,因此要查看此...
对于 Mac:进入您的 git 项目并输入:
以查看其中的所有提交,或者:
查看其中的所有提交,
然后您可以在任何您喜欢的浏览器中进行编辑。
We'll
git log
sometimes is not good to get all commits detail, so to view this...For Mac: Get into you git project and type:
to view you all commits in that, or:
to view you all commits in that,
then you can edit in any of your favourite browser.
@bsimmons
然后为每个分支创建一个分支:
现在许多工具将向您显示那些丢失的提交的图形可视化。
@bsimmons
Then create a branch for each one:
Now many tools will show you a graphical visualization of those lost commits.
如果您使用 Git 扩展 GUI,如果您选中“查看 -> 显示引用日志引用”,它可以向您显示悬空提交的图形可视化。
这将显示树中的悬空提交,就像所有其他引用的提交一样。这样就可以更轻松地找到您要查找的内容。
请参阅此图片进行演示。图像上的提交 C2、C3、C4 和 C5 是悬空的,但仍然可见。
If you use Git Extensions GUI it can show you a graphical visualization of dangling commits if you check "View -> Show reflog references".
This will show dangling commits in the tree, just like all other referenced ones. This way it is way easier to find what you are looking for.
See this image for demonstration. Commits C2, C3, C4, and C5 on the image are dangling but still visible.