3

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!

8

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.

enter image description here

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.

4
  • 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. Feb 1 at 13:07
  • 1
    You're welcome. I don't know for sure but I didn't find the possibility to search only the added lines.
    – Marioba
    Feb 1 at 20:05
  • Thanks for checking, much appreciated. Feb 2 at 3: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. ![enter image description here](i.stack.imgur.com/Qse43.png)
    – RoyM
    Apr 9 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.