我使用提交消息“Build 0051”检查了一些源代码到GIT中。 git
可是,我彷佛没法再找到源代码 - 如何使用命令行从GIT存储库中提取此源代码? 正则表达式
更新 express
更新 安全
源代码确定存在,如今须要检查它: ide
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>
虽然有点晚,可是:/
是基于提交消息指定提交(或修订)的专用符号,只需在搜索字符串前加上:/
,例如: ui
git show :/message
这里的<message>
能够是由空格组成的复杂正则表达式模式,所以请务必在必要时引用/转义,例如: spa
git log -1 -p ":/a few words"
或者,能够指定起始点,以查找从特定点可到达的最近提交,例如: 命令行
git show 'HEAD^{/fix nasty bug}'
请参阅: git修订手册 。 日志
首先使用git log --oneline
查找提交的SHA(Message),而后我使用git log --stat 8zad24d
和SHA(第一对情侣sha char示例(8zad24d))来查找正确的信息code
试试这个!
git log | grep -b3 "Build 0051"
要搜索给定文本的提交日志(跨全部分支):
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
做为您的安全网。 在列出的其中一个提交中查找Build 0051
git reflog
您可能只是将HEAD
设置为历史记录的一部分,其中“Build 0051”提交不可见,或者您可能实际上将其吹走了。 git-ready reflog文章可能会有所帮助。
要从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
git log --grep=<pattern> Limit the commits output to ones with log message that matches the specified pattern (regular expression).