如何通过提交消息来搜索Git存储库? [英] How to search a Git repository by commit message?

查看:92
本文介绍了如何通过提交消息来搜索Git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用提交消息Build 0051检查了一些源代码到GIT中。

然而,我似乎无法再找到源代码 - 使用命令行从GIT存储库中提取此源代码?



更新


  1. 使用SmartGIT检入0043,0044,0045和0046版本。

  2. 检出0043,并在不同分支上检查最多0051的版本。

  3. 再次检出0043。

  4. 现在,0051已经消失。

更新



源代码绝对存在,现在只需检查它即可:

  C:\ Source> git log -g --grep =0052
commit 77b1f718d19e5cf46e2fab8405a9a0859c9c2889
Reflog:HEAD @ {10}(未知< Mike @。(none)>)
Reflog消息:commit:20110819 - 1724 - GL:中间版本。文件版本:v0.5.0 build 0052.
作者:未知< Mike @。(none)>
日期:星期五8月19日17:24:51 2011 +0100

20110819 - 1724 - GL:中级版本。文件版本:v0.5.0 build 0052.

C:\ Source>

更新
<使用以下命令来检索丢失的源代码:

  C:\ Source> GT; git checkout HEAD @ {10} 
之前的头位是aa09ace ... 20110819 - 1045 - GL:中级版本。文件版本:v0.5.0 build 0043.
HEAD现在是77b1f71 ... 20110819 - 1724 - GL:中间版本。文件版本:v0.5.0 build 0052.

现在,SmartGit中的所有内容都可以再次显示。问题解决了 - 你们是最好的,尤其是@shelhamer!

解决方案

搜索提交日志给出的文本:

  git log --all --grep ='Build 0051'

要通过回购的历史记录搜索提交的实际内容,请使用:

  git grep'Build 0051'$(git rev-list --all)

显示给定文本的所有实例,包含文件名和提交sha1。

最后,如果您的提交悬而未决你可以使用 -g 标志搜索reflog本身(简称为 - walk-reflogs

  git log -g --grep ='Build 0051'

编辑:如果您好像丢失了历史记录,请检查 reflog 作为您的安全网。在其中一个提交中创建0051由

列出

  git reflog 

您可能简单地将您的 HEAD 设置为Build 0051提交不可见的历史记录部分,或者您可能实际上已经完成它走了。 git-ready reflog 文章可能为帮助。
$ b

要从reflog中恢复您的提交:对您找到的提交进行git签出(并可选择创建新的分支或标签(仅供参考)

  git checkout 77b1f718d19e5cf46e2fab8405a9a0859c9c2889 
#另类,使用reflog(请参阅提供的git-ready链接)
#git checkout HEAD @ {10}
git checkout -b build_0051#使用build_0051作为提示创建一个新分支


I checked some source code into GIT with the commit message "Build 0051".

However, I can't seem to find that source code any more - how do I extract this source from the GIT repository, using the command line?

Update

  1. Checked in versions 0043, 0044, 0045 and 0046 using SmartGIT.
  2. Checked out 0043, and checked in versions up to 0051 on a different branch.
  3. Checked out 0043 again.
  4. Now, 0051 has disappeared.

Update

The source code is definitely there, now its a matter of checking it out:

C:\Source>git log -g --grep="0052"
commit 77b1f718d19e5cf46e2fab8405a9a0859c9c2889
Reflog: HEAD@{10} (unknown <Mike@.(none)>)
Reflog message: commit: 20110819 - 1724 - GL: Intermediate version. File version:  v0.5.0 build 0052.
Author: unknown <Mike@.(none)>
Date:   Fri Aug 19 17:24:51 2011 +0100

    20110819 - 1724 - GL: Intermediate version. File version: v0.5.0 build 0052.

C:\Source>

Update

Used the following to retrieve the lost source code:

C:\Source>git checkout HEAD@{10}
Previous HEAD position was aa09ace... 20110819 - 1045 - GL: Intermediate version. File     version: v0.5.0 build 0043.
HEAD is now at 77b1f71... 20110819 - 1724 - GL: Intermediate version. File version: v0.5.0 build 0052.

Now, everything is visible in SmartGit again. Problem solved - you guys are the best, especially @shelhamer!

解决方案

To search the commit log (across all branches) for the given text:

git log --all --grep='Build 0051'

To search the actual content of commits through a repo's history, use:

git grep 'Build 0051' $(git rev-list --all)

to show all instances of the given text, the containing file name, and the commit sha1.

Finally, as a last resort in case your commit is dangling and not connected to history at all, you can search the reflog itself with the -g flag (short for --walk-reflogs:

git log -g --grep='Build 0051'

EDIT: if you seem to have lost your history, check the reflog as your safety net. Look for Build 0051 in one of the commits listed by

git reflog

You may have simply set your HEAD to a part of history in which the 'Build 0051' commit is not visible, or you may have actually blown it away. The git-ready reflog article may be of help.

To recover your commit from the reflog: do a git checkout of the commit you found (and optionally make a new branch or tag of it for reference)

git checkout 77b1f718d19e5cf46e2fab8405a9a0859c9c2889
# alternative, using reflog (see git-ready link provided)
# git checkout HEAD@{10}
git checkout -b build_0051 # make a new branch with the build_0051 as the tip

这篇关于如何通过提交消息来搜索Git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆