Home > Software engineering >  How can I retrieve all commits that changed files with one or two kinds of extensions?
How can I retrieve all commits that changed files with one or two kinds of extensions?

Time:10-25

How can I retrieve all commits that changed files with one or two kinds of extensions, e.g. ".YAML" and ".JSON"?

CodePudding user response:

git log --no-merges --oneline --name-status -- :*.yaml :*.json

with --oneline and --name-status basically being eye candy here.

The reason for the --no-merges is, a merge is of all the changes in the merged histories, so all the files that changed in that merge from either parent count. But since you're not restricting the walkback, you're going to see the commits that originally made those changes anyway (and git log knows this, and generally doesn't show diffs for merge commits anyway as that gets repetitive and increasingly worse-than-useless as histories get larger).

--first-parent rather than --no-merges with selected paths tells you which files were changed relative only to the first parent by the (no longer excluded) merges; rather than showing you the individual merged commits that changed those files it shows you the merges that brought those changes into the first-parent history you've got checked out.

git log with paths and neither --first-parent nor --no-merges turns out to be useful only as a forensics kind of query.

  • Related