Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

git - 如何通过提交消息搜索Git存储库?(How to search a Git repository by commit message?)

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

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

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?

(但是,我似乎无法再找到源代码 - 如何使用命令行从GIT存储库中提取此源代码?)

Update

(更新)

  1. Checked in versions 0043, 0044, 0045 and 0046 using SmartGIT.

    (使用SmartGIT检查版本0043,0044,0045和0046。)

  2. Checked out 0043, and checked in versions up to 0051 on a different branch.

    (检出0043,并检查其他分支上的版本0051。)

  3. Checked out 0043 again.

    (再次检查0043。)

  4. Now, 0051 has disappeared.

    (现在,0051已经消失了。)

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>
  ask by Contango translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

(显示给定文本的所有实例,包含文件名和提交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 :

(最后,作为最后的手段,如果您的提交悬空并且根本没有连接到历史记录,您可以使用-g标志搜索reflog本身( --walk-reflogs :)

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

EDIT: if you seem to have lost your history, check the reflog as your safety net.

(编辑:如果您似乎丢失了历史记录,请将reflog作为您的安全网。)

Look for Build 0051 in one of the commits listed by

(在列出的其中一个提交中查找Build 0051)

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.

(您可能只是将HEAD设置为历史记录的一部分,其中“Build 0051”提交不可见,或者您可能实际上将其吹走了。)

The git-ready reflog article may be of help.

(git-ready reflog文章可能会有所帮助。)

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)

(要从reflog中恢复您的提交 :执行您找到的提交的git checkout(并可选择创建一个新的分支或标记以供参考))

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...