Linux command
git-show-ref 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all refs
git show-ref
Show heads only
git show-ref --heads
Show tags only
git show-ref --tags
Verify ref exists
git show-ref --verify refs/heads/main
Quiet mode
git show-ref -q --verify refs/heads/main
说明
git show-ref lists references in the local repository, showing SHA-1 hashes and ref names for branches, tags, and other refs. It is a plumbing command commonly used in scripts. The verify mode checks whether a specific ref exists without listing all refs, returning an appropriate exit code.
参数
- --head
- Include the HEAD reference, which is filtered out by default.
- --branches
- Limit to local branches (refs/heads). Replaces the older --heads, which still works as an alias.
- --tags
- Limit to local tags (refs/tags).
- --verify
- Require the argument to be an exact ref path (e.g. refs/heads/main). Errors if the ref does not exist.
- --exists _ref_
- Check whether a ref exists. Exit code 0 = exists, 2 = missing, 1 = error.
- --exclude-existing=_pattern_
- Filter mode. Reads refs from stdin and prints those that do not exist locally, optionally limited to refs matching the pattern suffix.
- -q, --quiet
- Suppress output. Use the exit code only.
- -s, --hash=_N_
- Print only the object name (optionally abbreviated to _N_ hex digits), not the ref name.
- --abbrev=_N_
- Abbreviate the printed object name to _N_ hex digits (default uses core.abbrev).
- -d, --dereference
- For tag objects, also print the dereferenced commit, suffixed with ^{}.
FAQ
What is the git-show-ref command used for?
git show-ref lists references in the local repository, showing SHA-1 hashes and ref names for branches, tags, and other refs. It is a plumbing command commonly used in scripts. The verify mode checks whether a specific ref exists without listing all refs, returning an appropriate exit code.
How do I run a basic git-show-ref example?
Run `git show-ref` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --head do in git-show-ref?
Include the HEAD reference, which is filtered out by default.