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: git diff --name-status lists changed files with a letter for what happened

Git
~/tips/tip-git-diff-name-only-name-status

git diff --name-only main...HEAD

Lists only the files that changed, either as plain names or with a status letter for added, modified or deleted.

A full diff is too much when the only question is which files changed. Two options shrink the answer to a short list.

git diff --name-only main...HEAD
git diff --name-status main...HEAD

--name-only shows just the path of each changed file. --name-status adds a letter in front: A for added, M for modified, D for deleted, R for renamed, C for copied, T for a type change and U for unmerged.

The three dots in main...HEAD compare your branch against the point where it split off from main, so you see what your branch changed and not what main did meanwhile.

That list is easy to pass on to another command, for example to run a linter on changed files only:

git diff --name-only --diff-filter=d main...HEAD | xargs -r prettier --check

The --diff-filter=d part leaves out deleted files, which would otherwise make the tool fail. The caveat is quoting. Names with unusual characters are printed in quotes unless you use -z, which separates names with NUL bytes, so combine it with xargs -0 for such repositories. It also helps to remember that renamed files show up as R with a similarity score, which is the quickest way to see that a file moved rather than being rewritten.

Further reading: git-diff documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link