I want to supply my linter tool with files that changed in my branch. The list should include:
It should not include files that are changed in the parent branch since changing off. Thus if my branch doesn't have the latest commits from the parent branch that shouldn't matter.
What I tried so far:
git diff --name-only
gives my only what's changed, but not committed/stagedgit diff --name-only --staged
gives my only what's staged, but not committed/changedgit diff --name-only main...
gives my only what's committed but not changed/stagedgit diff --name-only main
gives everything (committed/staged/changed), but also includes what changed in main
In some way I already have my list if I combine the output of 1, 2 & 3. But it would be nice to have a single command. Is there something like that?
You're so close. git diff main...
is defined as
git diff A...B
is equivalent togit diff $(git merge-base A B) B
and you don't want it comparing against the second tip, your currently-checked-out commit, you want the default comparison, against the work tree, so you want to leave the last B
off there.
git diff $(git merge-base main @)
What's confusing you may be that in revision expressions a missing revision name generally defaults to HEAD
aka @
, whereas in a command argument list a missing argument that isn't necessarily a revision name does not default to HEAD
. So when you say main...
it's using HEAD
as the B
rev above.