Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude some tags from `git log`?

Tags:

git

I have a repository with an automated process that creates a lot of tags. Example:

* 5391e27 - (HEAD -> master, origin/master) Add a webhook to notify Phabricator of builds (2 hours ago) <Phil Frost>
* c380a48 - Retry downloading Selenium 3 times (2 hours ago) <Phil Frost>
| * 542731c - (tag: phabricator/diff/962) Retry downloading Selenium 3 times (6 hours ago) <Phil Frost>
|/
* 59509a3 - (tag: phabricator/base/962) Notify only on "master" branch (7 hours ago) <Phil Frost>
* 1504aa6 - Fix a few errors and omissions in README (7 hours ago) <Phil Frost>
| * a52940d - (tag: phabricator/diff/959) Notify only on "master" branch (3 days ago) <Phil Frost>
|/
| * 25838f0 - (tag: phabricator/diff/958) Notify only on "master" branch (3 days ago) <Phil Frost>
|/
* d7b3f72 - (tag: phabricator/base/959, tag: phabricator/base/958) Execute arbitrary commands in the test container (3 days ago) <Phil Frost>

Usually, I don't care about all these phabricator/*/* tags, so I'd like to see the log for all refs, except those. In other words, I want to see this:

* 5391e27 - (HEAD -> master, origin/master) Add a webhook to notify Phabricator of builds (2 hours ago) <Phil Frost>
* c380a48 - Retry downloading Selenium 3 times (2 hours ago) <Phil Frost>
* 59509a3 - Notify only on "master" branch (7 hours ago) <Phil Frost>
* 1504aa6 - Fix a few errors and omissions in README (7 hours ago) <Phil Frost>
* d7b3f72 - Execute arbitrary commands in the test container (3 days ago) <Phil Frost>

I'd think this would do it:

git log --exclude='refs/tags/phabricator/*/*' --all

Unfortunately, --exclude seems to have no effect any way I try it. How can I see all refs in the git log, except some tags that match a pattern?

like image 804
Phil Frost Avatar asked Dec 11 '22 17:12

Phil Frost


2 Answers

As an alternative, with Git 2.16 (Q1 2018), the tagnames "git log --decorate" uses to annotate the commits can now be limited to subset of available refs with the two additional options, --decorate-refs[-exclude]=<pattern>.

See commit 65516f5 (21 Nov 2017) by Rafael Ascensão (``).
Helped-by: Kevin Daudt (Ikke), and Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 6c3daa2, 13 Dec 2017)

log: add option to choose which refs to decorate

When log --decorate is used, git will decorate commits with all available refs. While in most cases this may give the desired effect, under some conditions it can lead to excessively verbose output.

Introduce two command line options,

  • --decorate-refs=<pattern> and
  • --decorate-refs-exclude=<pattern>
    to allow the user to select which refs are used in decoration.

When "--decorate-refs=<pattern>" is given, only the refs that match the pattern are used in decoration. The refs that match the pattern when "--decorate-refs-exclude=<pattern>" is given, are never used in decoration.

In your case:

git log -n6 --decorate=short --pretty="tformat:%f%d" \
        --decorate-refs-exclude="tags/phabricator/*"

With Git 2.27 (Q2 2020), the "--decorate-refs" and "--decorate-refs-exclude" options "git log" takes have learned a companion configuration variable log.excludeDecoration that sits at the lowest priority in the family.

See commit a6be5e6, commit c9f7a79 (16 Apr 2020) by Derrick Stolee (derrickstolee).
(Merged by Junio C Hamano -- gitster -- in commit d3fc8dc, 28 Apr 2020)

log: add log.excludeDecoration config option

Helped-by: Junio C Hamano
Signed-off-by: Derrick Stolee

In 'git log', the --decorate-refs-exclude option appends a pattern to a string_list.
This list is used to prevent showing some refs in the decoration output, or even by --simplify-by-decoration.

Users may want to use their refs space to store utility refs that should not appear in the decoration output. For example, Scalar runs a background fetch but places the "new" refs inside the refs/scalar/hidden/<remote>/* refspace instead of refs/<remote>/* to avoid updating remote refs when the user is not looking.
However, these "hidden" refs appear during regular 'git log' queries.

A similar idea to use "hidden" refs is under consideration for core Git.

Add the 'log.excludeDecoration' config option so users can exclude some refs from decorations by default instead of needing to use --decorate-refs-exclude manually.
The config value is multi-valued much like the command-line option.
The documentation is careful to point out that the config value can be overridden by the --decorate-refs option, even though --decorate-refs-exclude would always "win" over --decorate-refs.

Since the 'log.excludeDecoration' takes lower precedence to --decorate-refs, and --decorate-refs-exclude takes higher precedence, the struct decoration_filter needed another field. This led also to new logic in load_ref_decorations() and ref_filter_match().

like image 187
VonC Avatar answered Dec 25 '22 22:12

VonC


This probably should work (and might eventually):

git log --exclude='refs/tags/phabricator/*/*' --all

I think the problem is the */*; try it with --exclude='refs/tags/phabricator/*'. There are various places where * can only occur at the end of a name, and this is one of them. (Fetch refspecs also used to be limited like this but that limitation was removed recently.)

Note that --decorate will still add refs/tags/phabricator/foo/bar to a commit that is included via --all that happens also to be tagged (if there are any such). That is, the --exclude step keeps such commits from being added, but not from being decorated if they are already included.

like image 36
torek Avatar answered Dec 25 '22 22:12

torek