brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh pr diff --exclude hides lockfiles and generated files from a pull request diff

CLI
~/tips/tip-github-pr-diff-exclude

gh pr diff 123 --exclude '*.lock'

Prints a pull request's diff in the terminal and leaves out files that match a glob.

Some pull requests are 40 lines of real change and 6,000 lines of lockfile. Reading that in the browser means a lot of scrolling past noise. The GitHub CLI can print the diff in your terminal and skip the files you do not care about.

gh pr diff 123 --exclude '*.lock'

Without an argument, gh pr diff picks the pull request that belongs to the current branch. With a number, URL or branch name it shows that one. --exclude (short form -e) takes a glob pattern, and you can repeat the flag. Per the help text, the pattern uses forward slashes as path separators on all platforms. The examples in the built-in help look like this:

gh pr diff --exclude '*.yml' --exclude 'generated/*'
gh pr diff --name-only --exclude '*.generated.*'

The second one is my favourite for a first look: --name-only lists just the names of the changed files, and combined with --exclude you see how big the real change is before you read any of it.

The other flags from gh pr diff --help:

  • --patch shows the diff in patch format.
  • --color takes always, never or auto, with auto as the default.
  • -w opens the diff in the browser instead.

Caveats. Put the pattern in quotes, otherwise your shell tries to expand *.lock against the files in the current folder before gh sees it. And gh has to be logged in, with gh auth login, since it talks to GitHub for the diff. I wrote this from the help text and the manual, so check the exact glob matching on your own repository before you rely on it.

Further reading: gh pr diff manual

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link