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
189 views
in Technique[技术] by (71.8m points)

Difference between different git search commands

A question from a beginner: there are several ways to search in git history. To me, it is not clear what, the difference between the commands really is:

  1. git log, e.g. git log -S 'for what you search' --all to search for a string in all branches and git log -G 'search for regexpr' --all to search for regexpr. See for example here
  2. git log --grep 'pattern'
  3. git rev-list, e.g. git rev-list --grep='string' --all
  4. git grep, e.g. git grep "string or regexpr" $(git rev-list --all) from here
  5. gitk, e.g. gitk file.txt a gui interface
  6. git log --all --full-history -- **/thefile.* to search for a filename in history from here.
  7. git diff --word-diff-regex=. > changes.txt combined with grep -oP '+[^+]++' changes.txt | tr -d '+' to display changes on a character basis. From here. This even works if changes are not commited yet.

My poor understanding is that

  • git log searches in the commit messages? It seems to be based on rev-list? From the docs:

Shows the commit logs. The command takes options applicable to the git rev-list command to control what is shown and how, and options applicable to the git diff-* commands to control how the changes each commit introduces are shown.

  • git-rev-list seems to be a more basic command as it operates on the commit object (or tree object?). From the docs:

git-rev-list - Lists commit objects in reverse chronological order

  • git grep seems to search everywhere: in files, blobs, trees and commit objects? From the docs:

git-grep - Print lines matching a pattern. Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. Patterns are lists of one or more search expressions separated by newline characters. An empty string as search expression matches all lines.

I used the Git book as reference.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

git log searches in the commit messages?

Yes. Options -S/-G search for commits that change the number of occurence (i.e., add or remove) mentioned text. --grep searches through entire commit messages.

git grep seems to search everywhere: in files, blobs, trees and commit objects?

No, only in files (that is, blobs).


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

...