Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log suppress refs matching specified pattern

Tags:

git

regex

git-log

I regularly use the following git-log command:

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

The command is perfect for me, with one exception. I maintain a set of refs in refs/arch/ that I want to keep around ("arch" stands for "archive"), but I do not want to see them every time I look at my git log. I don't mind them showing up if they are an ancestor of an existing branch or tag, but I really do not want to see series of commits that would not otherwise show up in the git log but for the fact that they are in the commit history of a given refs/arch/* ref.

For example, in the image below, the left-hand side is an illustration of what I see currently when I run git log --oneline --graph --decorate --all. As you can see, the commit referred to by refs/arch/2 would not show up in the log if that ref didn't exist. (Assume there are no refs that are not shown in the left-hand side image.) Now, the right-hand side is an illustration of two alternative log graphs, either of which would be perfectly fine. I don't mind seeing anything matching refs/arch/* so long as it is in the commit history of a branch or tag. But, in the image below, I definitely do not want to see the commit referred to by refs/arch/2.

Illustration of question

How can my git-log command be modified to suppress refs/arch/* in either of the senses depicted in the illustration?

like image 327
synaptik Avatar asked Aug 30 '14 17:08

synaptik


1 Answers

What you want is:

git log --oneline --graph --decorate --exclude 'refs/arch/*' --all

The --exclude option is new in git 1.9.0.


From the git-log manual page:

--exclude=<glob-pattern>

Do not include refs matching <glob-pattern> that the next --all, --branches, --tags, --remotes, or --glob would otherwise consider. Repetitions of this option accumulate exclusion patterns up to the next --all, --branches, --tags, --remotes, or --glob option (other options or arguments do not clear accumlated patterns).

The patterns given should not begin with refs/heads, refs/tags, or refs/remotes when applied to --branches, --tags, or --remotes, respectively, and they must begin with refs/ when applied to --glob or --all. If a trailing /* is intended, it must be given explicitly.


If you are on some flavor of Ubuntu you can upgrade git from the Ubuntu Git Maintainers team ppa.

  1. sudo add-apt-repository ppa:git-core/ppa
  2. sudo apt-get update
  3. sudo apt-get upgrade
like image 83
user3942918 Avatar answered Nov 10 '22 02:11

user3942918