I am constantly surprised by the number of features provided by git. This week, while trying to figure out how to list the commits from the Linux UEFI Validation project that are not part of the meta-luv layer and also not part of upstream Poky, I came across a useful trick on stackoverflow - git pathspec magic.

Commits not inside meta-luv and not sent to Poky represent the technical debt for the LUV project. Ideally the only changes we make outside of the meta-luv layer would also be sent upstream. That's not always possible, so at the very least, we need a way of finding those changes to track them.

The trick goes like this... If you want to list all commits apart from those relating to a particular subdirectory, use the ":exclude" pathspec magic,

  git log -- . ":(exclude)directory"
This is superb for the LUV project because most of the project's significant changes are in the meta-luv directory, which is a separate layer hosted on git.yoctoproject.org. What we want to find is those commits that are not part of meta-luv.

To recap, the way to display just those commits that are not part of upstream Poky dora release is,

  git log poky/dora..HEAD
But the resultant list of commits includes those that are part of the meta-luv layer. We don't want those commits, we just want to see those that are not part of the meta-luv layer and not part of Poky.

The trick goes like this,

  git log poky/dora..HEAD -- . ":(exclude)meta-luv"
Pathspecs can be applied to all git commands that deal with paths, though documentation for git pathspecs isn't actually easy to find. You won't find it as part of the git-log man page. The best bet is to take a look at gitglossary,


pathspec
Pattern used to limit paths in Git commands.

...

A pathspec that begins with a colon : has special meaning. In the
short form, the leading colon : is followed by zero or more "magic
signature" letters (which optionally is terminated by another colon
:), and the remainder is the pattern to match against the path.

...

exclude
After a path matches any non-exclude pathspec, it will be run
through all exclude pathspec (magic signature: !). If it
matches, the path is ignored.