Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show log of commits affecting files matching a pattern whose diff also matches a pattern

I want to view a git log of commits that obey all of the following:

  1. The commit modifies a file whose name matches a given pattern.
  2. The commit changes the number of occurrences of a pattern in a file (essentially, what --pickaxe-regex -S does).
  3. The change matching rule 2 does not necessarily occur in the file matching rule 1.

Basically, I want to combine Show all commits whose diff contain specific string and Find commits that modify file names matching a pattern in a GIT repository. Just combining those two techniques, as I’ve done below, satisfies rules 1 & 2, but not 3.

So far I have:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

git log --pickaxe-regex -S 'ChangePattern|SomeAlternatePattern' -- '*/filename.txt'

This works as long as the change occurs in filename.txt; however, the change I am looking for is in a different file than the one that is being matched by the pattern.

>Solution :

You can combine git log and git show :

# have `git log` just output the hash of selected commits :
git log --format="%H" --pickaxe-regex -S 'ChangePattern|SomeAlternatePattern' |\
  # `git show` will not output anything if commit doesn't modify any of the files
  while read sha; do git show $sha -- '*/filename.txt'; done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading