103

I have a Git alias that expands to:

git log --graph --oneline --all --decorate

According to man git log there are a couple of suspicious options: --not and --branches; but I can't make it work properly.

How should I edit that to hide the stashes?


FYI: as per the accepted question and comment my .gitconfig alias now looks like this:

[alias]
    l = log --branches --remotes --tags --graph --oneline --decorate --notes HEAD

3 Answers 3

141

Instead of doing --all and then trying to filter out the stashes, don't ever include them in the first place:

git log --branches --remotes --tags --graph --oneline --decorate

The main problem that arises from trying to filter them out afterwards is that if the stash is the latest commit on that branch (because even though it's not the head of the branch, it's still the most recent descendant of it), it can actually filter out the entire branch from the log, which isn't what you want.

3
  • I'd suspect --tags to be redundant, since no tag should ever be a descendant of the head of a branch or remote, though I haven't verified this. Feb 24, 2012 at 23:17
  • 5
    Just tried this: git checkout -b test; added a commit ; git tag foo ; git checkout master ; git branch -D test. The tag is there but it will not be shown without --tags.
    – cYrus
    Feb 24, 2012 at 23:20
  • 3
    One small addition -- you should add HEAD to the end. Otherwise, if you're in detached HEAD mode and no other ref points to the HEAD commit, you won't see it in the graph.
    – mziwisky
    Mar 5, 2015 at 19:52
15

My alias:

[alias]
    l = log --oneline --decorate --graph --exclude=refs/stash

In this case you will be able to use these forms without showing the stash:

  • git l for the current branch
  • git l feature234 for a specific branch
  • git l --all for the overall history

From the manual:

--exclude=<glob pattern>

Do not include refs matching that the next --all, --branches, --tags, --remotes, or --glob would otherwise consider.

1
  • 9
    Note that the order of parameters matters: --all --exclude=refs/stash would still include the stash, while --exclude=refs/stash --all would correctly exclude it. Jun 6, 2018 at 7:32
5

Note that Andrew's answer wouldn't work for hiding StGit1.) branches <branch>.stgit (from StGit version 0.15) which otherwise litter the output making it unusable.

Currently I use the following solution:

$ git log --graph --oneline --decorate \
  $(git for-each-ref --format="%(refname)" refs/heads/ refs/remotes/ |
    grep -v "\.stgit$")

1.) StGit ("Stacked Git") provides Quilt/mq--like functionality to Git (i.e. pushing/popping patches to/from a stack).

1
  • Consider using --exclude. Like: git log --graph --exclude=refs/heads/*.stgit --exclude=refs/patches/* --exclude=refs/stash --all
    – gavenkoa
    Jun 12, 2018 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.