I am using Magit and was wondering how to revert to a specific commit that contained a specific expression. First I need to find the expression across all commits content. How to do this? In command line it would be something like git grep / git log. Thanks!
1 Answers
In Magit:
Open the Magit log buffer with ll (lowercase
L
twice).Customize the log with L and search for commit messages with -F or for changes with -G.
Once you entered your search value, press RET and refresh the buffer with g. You will see only commits that match your search.
Or you can directly open the log buffer with your options with l → set your options → l.
In git documentation https://git-scm.com/docs/git-log#Documentation/git-log.txt--Sltstringgt you can find more information about how to use the -G
option
-G
Look for differences whose patch text contains added/removed lines that match . To illustrate the difference between -S --pickaxe-regex and -G, consider a commit with the following diff in the same file:
- return frotz(nitfol, two->ptr, 1, 0); ...
- hit = frotz(nitfol, mf2.ptr, 1, 0);
While git log -G"frotz(nitfol" will show this commit, git log >-S"frotz(nitfol" --pickaxe-regex will not (because the number of >occurrences of that string did not change).
Unless --text is supplied patches of binary files without a textconv >filter will be ignored.
-
This is fantastic, exactly to the point, what I needed! Just out of curiosity, is it possible to search for only commits where the regex is added, not deleted? Thanks. – Emmanuel Goldstein Feb 01 '21 at 13:07
-
1You're welcome. I don't know for sure but I didn't find the possibility to search only the added lines. – Marioba Feb 01 '21 at 20:05
-
Thanks for checking, much appreciated. – Emmanuel Goldstein Feb 02 '21 at 03:44
-
Great answer.. to add to the discussion, if I understand correctly, using the `-p` flag gives you the specific patches (diffs) that involve the pattern searched for. [](https://i.stack.imgur.com/Qse43.png) – RoyM Apr 09 '21 at 12:19
-
2How to set `ignore case` e.g. show `Foo` if searching for `foo`? – jjk Feb 20 '22 at 07:59
-
How to search within the whole text not of the commit message, but of the files? – Adelita Oct 26 '22 at 04:53
-
"and refresh the buffer with g". I don't have "g" option. Any ideas? – Adelita Jan 31 '23 at 16:33