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 Answer
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. Commented Feb 1, 2021 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.– MariobaCommented Feb 1, 2021 at 20:05
-
-
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. ![enter image description here](i.sstatic.net/Qse43.png)– RoyMCommented Apr 9, 2021 at 12:19 -
2