获取所有 git 提交的列表,包括“丢失”的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4786972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get a list of all git commits, including the 'lost' ones
提问by Amadan
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.
如果我这样做git log --all --oneline
,我将获得所有六个提交。
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?
我不会看到 E 和 F。我可以让 git 告诉我所有的提交,包括那些没有命名的分支上的提交吗?
Thanks
谢谢
采纳答案by araqnid
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 a git 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.
不是特别容易——如果你丢失了指向树枝尖端的指针,就像大海捞针一样。您可以找到所有似乎不再被引用的提交-git fsck --unreachable
将为您执行此操作-但这将包括您在 a 之后丢弃的git commit --amend
提交,您重新定位的分支上的旧提交等。所以查看所有这些提交一次很可能是太多信息无法浏览。
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.
所以轻率的答案是,不要忘记你感兴趣的事情。更严重的是,默认情况下,reflogs 将保存对你过去 60 天左右使用的所有提交的引用。更重要的是,他们会给出一些关于这些提交是什么的上下文。
回答by kenorb
Try:
尝试:
git log --reflog
which lists all git commits by pretending that all objects mentioned by reflogs (git reflog
) are listed on the command line as <commit>
.
它通过假装 reflogs( git reflog
)提到的所有对象在命令行中列为.git 来列出所有提交<commit>
。
回答by Kieran
When I tackle this issue I use the following command:
当我解决这个问题时,我使用以下命令:
git reflog | awk '{ print }' | xargs gitk
This lets me visualise recent commits which have become headless.
这让我可以想象最近已经变得无头的提交。
I have this wrapped up in a script helper called ~/bin/git-reflog-gitk
.
我将其封装在一个名为~/bin/git-reflog-gitk
.
回答by Sonhja
What saved my life was the following command:
救了我一命的是以下命令:
git reflog
There you find a screen with history commits done to git like this one:
在那里你会找到一个屏幕,其中包含对 git 完成的历史提交,如下所示:
At this point, you only have to find the HEAD@{X}
that you need, create a temporary branch and move to it like this:
在这一点上,你只需要找到HEAD@{X}
你需要的,创建一个临时分支并像这样移动到它:
git checkout -b temp_branch HEAD@{X}
That way you will have a temporary branch with your lost commit without rebasing or breaking even more your git repository.
这样,您将拥有一个带有丢失提交的临时分支,而无需重新设置或破坏您的 git 存储库。
Hope this helps...
希望这可以帮助...
回答by Florian Fida
Like @Kieran 's Answer, but for the console:
git log --oneline --all --graph --decorate $(git reflog | awk '{print $1}')
就像@Kieran 的答案一样,但对于控制台:
git log --oneline --all --graph --decorate $(git reflog | awk '{print $1}')
回答by bsimmons
How I solve this problem? Use git fsck
and logging!
我如何解决这个问题?使用git fsck
和记录!
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!)
首先创建一个包含丢失(无法访问)提交和 blob 的文件。(注意:如果你做了类似的事情,git gc
那么它会垃圾收集他们所有的提交,你不会在这里找到它们!)
$git fsck --lost-found > lost_found.commits
That gives you a file like this:
这会给你一个这样的文件:
dangling commit dec2c5e72a81ef06963397a49c4b068540fc0dc3
dangling blob f8c2579e6cbfe022f08345fa7553feb08d60a975
dangling blob 0eb3e86dc112332ceadf9bc826c49bd371acc194
dangling blob 11cbd8eba79e01f4fd7f496b1750953146a09502
dangling commit 18733e44097d2c7a800650cea442febc5344f9b3
dangling blob 1e53a5cdb3ecdde27081ec6e8b31e4070106ee05
悬挂提交dec2c5e72a81ef06963397a49c4b068540fc0dc3
悬挂一滴f8c2579e6cbfe022f08345fa7553feb08d60a975
晃来晃去斑点0eb3e86dc112332ceadf9bc826c49bd371acc194
悬挂一滴11cbd8eba79e01f4fd7f496b1750953146a09502
悬挂承诺18733e44097d2c7a800650cea442febc5344f9b3
悬挂一滴1e53a5cdb3ecdde27081ec6e8b31e4070106ee05
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*)
然后你可以用你最喜欢的文本编辑器打开这个文件,从那里复制提交/博客哈希。(*咳咳* vim 宏对此非常有效 *咳咳*)
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.
现在,您可以使用类似git log --oneline <commit hash>
. 或者,gitk、tig 或任何其他 git 查看器应该可以工作。
In your case if you find the hash for commit F the log will show you something like this,
在您的情况下,如果您找到提交 F 的哈希值,日志将显示如下内容,
A---B---E---F
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)
PS 是的,我知道,迟到的帖子,但是哦,有人可能会在这里找到它并发现它很有用。(很可能是我在 6 个月内再次使用谷歌搜索时)
回答by GameScripting
I've had luck recovering the commit by looking at the reflog, which was located at .git/logs/HEAD
通过查看位于的引用日志,我很幸运地恢复了提交 .git/logs/HEAD
I then had to scoll down to the end of the file, and I found the commit I just lost.
然后我不得不向下滚动到文件的末尾,我找到了我刚刚丢失的提交。
回答by Vinod Joshi
We'll git log
sometimes is not good to get all commits detail, so to view this...
我们git log
有时无法获得所有提交的详细信息,因此要查看此...
For Mac: Get into you git project and type:
对于 Mac:进入你的 git 项目并输入:
$ nano .git/logs/HEAD
to view you all commits in that, or:
查看你所有的提交,或者:
$ gedit .git/logs/HEAD
to view you all commits in that,
查看你所有的提交,
then you can edit in any of your favourite browser.
然后您可以在任何您喜欢的浏览器中进行编辑。
回答by yakoda
@bsimmons
@bsimmons
git fsck --lost-found | grep commit
Then create a branch for each one:
然后为每个创建一个分支:
$ git fsck --lost-found | grep commit
Checking object directories: 100% (256/256), done.
dangling commit 2806a32af04d1bbd7803fb899071fcf247a2b9b0
dangling commit 6d0e49efd0c1a4b5bea1235c6286f0b64c4c8de1
dangling commit 91ca9b2482a96b20dc31d2af4818d69606a229d4
$ git branch branch_2806a3 2806a3
$ git branch branch_6d0e49 6d0e49
$ git branch branch_91ca9b 91ca9b
Now many tools will show you a graphical visualization of those lost commits.
现在,许多工具将向您展示那些丢失提交的图形可视化。
回答by Zdovc
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.
如果您使用 Git 扩展 GUI,如果您选中“查看 -> 显示 reflog 引用”,它可以向您显示悬空提交的图形可视化。这将在树中显示悬空提交,就像所有其他引用的提交一样。通过这种方式,可以更轻松地找到您要查找的内容。
See this imagefor demonstration. Commits C2, C3, C4, and C5 on the image are dangling but still visible.
请参阅此图像进行演示。图像上的提交 C2、C3、C4 和 C5 悬空但仍然可见。