Consider a Python configuration file with the following line:
THEME = 'gum'
The THEME
key appears only once, so when I want to know what the THEME
is, I grep the file:
grep THEME pelicanconf.py
The file is kept in git, and I would like to grep for THEME
in all previous git commits, in order to tell when was this line changed.
Is there an elegant way to grep the entire history of a git file?
Git ships with a command called grep that allows you to easily search through any committed tree, the working directory, or even the index for a string or regular expression.
On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.
`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.
The git grep version will only search in files tracked by git, whereas the grep version will search everything in the directory.
git log -S'THEME' -- pelicanconf.py | xargs -n 1 git show
shows the content of every commit that changed THEME
However, it prints out full commits, not only changes.
var="THEME"; git log -S"$var" -p -- pelicanconf.py | egrep "$var|commit|Date:"
would show you all variants of THEME
with commit hashes and dates.
Thx @knittl for -p
option.
Also, found a solution with gitk
: see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With