Home > Mobile >  git for-each-ref --filter returns nothing when filtering multiple fields
git for-each-ref --filter returns nothing when filtering multiple fields

Time:09-28

I'm trying to display all the current branches while applying filter criteria regarding what I want to see.

When I filter using only 1 field it's working but as soon as I include multiple fields it returns nothing.

For example this works (returns dates):

λ git for-each-ref --format='%(committerdate)' --sort=committerdate
'Tue Aug 10 15:32:14 2021  0200'
'Thu Sep 30 09:35:57 2021  0000'
'Fri Oct 22 09:54:05 2021  0000'
'Tue Nov 16 09:58:55 2021  0000'
'Tue Jul 19 12:20:46 2022  0000'
'Wed Sep 14 09:55:06 2022  0000'
'Wed Sep 14 09:55:06 2022  0000'
'Wed Sep 14 09:55:06 2022  0000'
'Wed Sep 14 09:55:06 2022  0000'
'Wed Sep 21 06:35:24 2022  0000'
'Tue Sep 27 05:44:38 2022  0000'
'Tue Sep 27 07:59:01 2022  0000'
'Tue Sep 27 07:59:01 2022  0000'

This works as well (returns branch names):

λ git for-each-ref --format='%(refname)' --sort=committerdate
'refs/tags/1.0.0'
'refs/tags/1.0.1'
'refs/tags/1.0.2'
'refs/tags/1.1.0'
'refs/tags/1.2.0'
'refs/heads/develop'
'refs/heads/master'
'refs/remotes/origin/HEAD'
'refs/remotes/origin/master'
'refs/remotes/origin/develop'
'refs/remotes/origin/bugfix/RPA0075-1363'
'refs/heads/release/1.3.0'
'refs/remotes/origin/release/1.3.0'

But as soon as I want both fields it returns nothing:

λ git for-each-ref --format='%(committerdate) %(refname)' --sort=committerdate

Any ideas on what I'm doing wrong?

CodePudding user response:

The problem is Windows-related. ' do not work as string delimiters in cmd.exe, but are part of regular words.

git for-each-ref --format='%(committerdate) %(refname)' --sort=committerdate

is parsed as:

git for-each-ref --format="'%(committerdate)" --sort=committerdate " %(refname)'"

since there is no branch with the name %(refname)', your output will be empty. To fix, switch to a shell with sensible quoting rules (e.g. Git Bash comes with Bash) or use double quotes:

git for-each-ref --format="%(committerdate) %(refname)" --sort=committerdate
  •  Tags:  
  • git
  • Related