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:
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
git log --grep 'pattern'
git rev-list
, e.g. git rev-list --grep='string' --all
git grep
, e.g. git grep "string or regexpr" $(git rev-list --all)
from here
gitk
, e.g. gitk file.txt
a gui interface
git log --all --full-history -- **/thefile.*
to search for a filename in history from here.
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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…