Skip to content
Advertisement

Filter output of git diff-tree based on file extension

git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHORT_SHA

gives me the list all the files that were committed for that SHA.

I am looking for a way to get a list of files with only .xml or .html extensions.

I checked the documentation page – here and couldn’t see any option.

Any help is greatly appreciated.

Advertisement

Answer

You can use -- <path> [<otherpath> ...] for this :

git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHORT_SHA -- *.xml *.html

Be sure to put it at the end of the command, with no options behind it, since git will treat anything past it as paths.

Doc from the git log page here, but this is usable for a lot of display commands.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement