← 返回命令列表

Linux command

git-for-each-ref 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

List all refs

git for-each-ref

List branches

git for-each-ref refs/heads

List tags

git for-each-ref refs/tags

Custom format

git for-each-ref --format='%(refname:short) %(objectname:short)' refs/heads

Sort by date

git for-each-ref --sort=-committerdate refs/heads

Show latest N refs

git for-each-ref --count=[10] --sort=-committerdate refs/heads

说明

git for-each-ref is a plumbing command that outputs detailed information about Git references (branches, tags, remote branches) in a highly customizable format. It serves as the foundation for many higher-level Git commands and scripts that need to process repository references. The format string syntax supports field extraction using %(fieldname) placeholders, with available fields including refname, objecttype, objectname, author, committer, and many others. Sorting capabilities enable ordering references by any field, with support for reverse sorting using a minus prefix. This command is primarily used in scripts and Git aliases rather than direct user interaction. The filtering options (--merged, --no-merged, --points-at) provide powerful selection mechanisms for finding references matching specific criteria.

参数

--format _format_
Output format string.
--sort _key_
Sort by key.
--count _n_
Limit output count.
--points-at _object_
Show refs pointing to object.
--merged _commit_
Show refs merged into commit.
--no-merged _commit_
Show refs not merged.

FAQ

What is the git-for-each-ref command used for?

git for-each-ref is a plumbing command that outputs detailed information about Git references (branches, tags, remote branches) in a highly customizable format. It serves as the foundation for many higher-level Git commands and scripts that need to process repository references. The format string syntax supports field extraction using %(fieldname) placeholders, with available fields including refname, objecttype, objectname, author, committer, and many others. Sorting capabilities enable ordering references by any field, with support for reverse sorting using a minus prefix. This command is primarily used in scripts and Git aliases rather than direct user interaction. The filtering options (--merged, --no-merged, --points-at) provide powerful selection mechanisms for finding references matching specific criteria.

How do I run a basic git-for-each-ref example?

Run `git for-each-ref` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --format _format_ do in git-for-each-ref?

Output format string.