Nice programing

커밋 메시지로 Git 저장소를 검색하는 방법은 무엇입니까?

nicepro 2020. 9. 29. 18:38
반응형

커밋 메시지로 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} (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>

주어진 텍스트에 대한 커밋 로그 (모든 분기에 걸쳐)를 검색하려면 :

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

저장소 기록을 통해 커밋의 실제 내용을 검색하려면 다음을 사용하십시오.

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

주어진 텍스트, 포함하는 파일 이름 및 커밋 sha1의 모든 인스턴스를 표시합니다.

마지막으로 커밋이 매달려 있고 히스토리에 전혀 연결되지 않은 경우 마지막 수단으로 -g플래그를 사용 하여 리플 로그 자체를 검색 할 수 있습니다 (줄임말 --walk-reflogs:

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

편집 : 역사를 잃어버린 것 같으면 reflog안전망으로 확인하십시오 . 다음에 나열된 커밋 중 하나에서 빌드 0051을 찾습니다.

git reflog

단순히 HEAD'Build 0051'커밋이 표시되지 않는 기록의 일부로 설정 했거나 실제로 날려 버릴 수 있습니다. 자식 준비 reflog의 기사는 도움이 될 수 있습니다.

reflog에서 커밋을 복구하려면 : 찾은 커밋을 git 체크 아웃하고 선택적으로 참조를 위해 새 브랜치 또는 태그를 만듭니다.

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

나는 이것을 ~ / .gitconfig에 넣습니다.

[alias]
    find = log --pretty=\"format:%Cgreen%H %Cblue%s\" --name-status --grep

Then I can type "git find string" and I get a list of all the commits containing that string in the message. For example, to find all commits referencing ticket #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

Though a bit late, there is :/ which is the dedicated notation to specify a commit (or revision) based on the commit message, just prefix the search string with :/, e.g.:

git show :/message

Here <message> can be a complex regex pattern consisting of whitespaces, so please make sure to quote/escape when necessary, e.g.:

git log -1 -p ":/a few words"

Alternatively, a start point can be specified, to find the closest commit reachable from a specific point, e.g.:

git show 'HEAD^{/fix nasty bug}'

See: git revisions manual.


git log --grep=<pattern>
            Limit the commits output to ones with log message that matches the
            specified pattern (regular expression).

git log --grep="Build 0051"

should do the trick


Try this!

git log | grep -b3 "Build 0051"

first use git log --oneline to find the SHA of the commit (Message), then I used git log --stat 8zad24d with the SHA (the first couples sha char example (8zad24d)) to find the right info

참고URL : https://stackoverflow.com/questions/7124914/how-to-search-a-git-repository-by-commit-message

반응형