我使用提交消息"Build 0051"检查了一些源代码到GIT中.
但是,我似乎无法再找到源代码 - 如何使用命令行从GIT存储库中提取此源代码?
更新
更新
源代码肯定存在,现在需要检查它:
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>
Run Code Online (Sandbox Code Playgroud)
更新
使用以下内容检索丢失的源代码:
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>
Run Code Online (Sandbox Code Playgroud)
现在,一切都在SmartGit中再次可见.问题解决了 - 你们是最好的,特别是@shelhamer!
she*_*mer 1176
要搜索给定文本的提交日志(跨所有分支):
git log --all --grep='Build 0051'
Run Code Online (Sandbox Code Playgroud)
要通过回购历史记录搜索提交的实际内容,请使用:
git grep 'Build 0051' $(git rev-list --all)
Run Code Online (Sandbox Code Playgroud)
显示给定文本的所有实例,包含文件名和提交sha1.
最后,作为最后的手段,如果您的提交悬空并且根本没有连接到历史记录,您可以使用-g标志搜索reflog本身(简称--walk-reflogs:
git log -g --grep='Build 0051'
Run Code Online (Sandbox Code Playgroud)
编辑:如果您似乎丢失了历史记录,请将其reflog作为您的安全网.在列出的其中一个提交中查找Build 0051
git reflog
Run Code Online (Sandbox Code Playgroud)
您可能只是将您设置HEAD为历史记录的一部分,其中"Build 0051"提交不可见,或者您可能实际上已将其炸毁.该混帐就绪引用日志 文章可能会有所帮助.
要从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
Run Code Online (Sandbox Code Playgroud)
Ale*_*sky 76
我把它放在我的〜/ .gitconfig中:
[alias]
find = log --pretty=\"format:%Cgreen%H %Cblue%s\" --name-status --grep
Run Code Online (Sandbox Code Playgroud)
然后我可以输入"git find string",我会得到一条包含该消息中所有字符串的提交列表.例如,要查找引用故障单#33的所有提交:
029a641667d6d92e16deccae7ebdeef792d8336b Added isAttachmentEditable() and isAttachmentViewable() methods. (references #33)
M library/Dbs/Db/Row/Login.php
a1bccdcd29ed29573d2fb799e2a564b5419af2e2 Add permissions checks for attachments of custom strategies. (references #33).
M application/controllers/AttachmentController.php
38c8db557e5ec0963a7292aef0220ad1088f518d Fix permissions. (references #33)
M application/views/scripts/attachment/_row.phtml
041db110859e7259caeffd3fed7a3d7b18a3d564 Fix permissions. (references #33)
M application/views/scripts/attachment/index.phtml
388df3b4faae50f8a8d8beb85750dd0aa67736ed Added getStrategy() method. (references #33)
M library/Dbs/Db/Row/Attachment.php
Run Code Online (Sandbox Code Playgroud)
rye*_*nus 32
虽然有点晚,但有:/一个专用符号来指定基于提交消息的提交(或修订),只需在搜索字符串前加上:/,例如:
git show :/message
Run Code Online (Sandbox Code Playgroud)
这里<message>可以是由空格组成的复杂正则表达式模式,因此请务必在必要时引用/转义,例如:
git log -1 -p ":/a few words"
Run Code Online (Sandbox Code Playgroud)
或者,可以指定起始点,以查找从特定点可到达的最近提交,例如:
git show 'HEAD^{/fix nasty bug}'
Run Code Online (Sandbox Code Playgroud)
请参阅:git修订手册.
Jos*_*Lee 21
git log --grep=<pattern>
Limit the commits output to ones with log message that matches the
specified pattern (regular expression).
Run Code Online (Sandbox Code Playgroud)
Nou*_*him 16
git log --grep="Build 0051"
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩
小智 10
只是对命令的一个小补充git log --all --grep:在我的例子中,我必须转义消息内的括号:
git log --all --grep="\[C\] Ticket-1001: Fix nasty things"
Run Code Online (Sandbox Code Playgroud)
试试这个!
git log | grep -b3 "Build 0051"
Run Code Online (Sandbox Code Playgroud)
小智 8
搜索所有分支
git log --all --grep='Build 0051'
Run Code Online (Sandbox Code Playgroud)
一旦你知道你想要进行哪个提交
git checkout <the commit hash>
Run Code Online (Sandbox Code Playgroud)
首先列出提交使用
git log --oneline
Run Code Online (Sandbox Code Playgroud)
然后找到提交的SHA(消息),然后我用
git log --stat 8zad24d
Run Code Online (Sandbox Code Playgroud)
(8zad24d) 是与您感兴趣的提交相关的 SHA(第一对夫妇 sha 示例 (8zad24d) 您可以选择 4 个字符或 6 或 8 个或整个 sha)以找到正确的信息
对于任何想要传递完全匹配的任意字符串(并且不用担心转义正则表达式特殊字符)的人,git log 采用 --fixed-strings 选项
git log --fixed-strings --grep "$SEARCH_TERM"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
340466 次 |
| 最近记录: |