为什么是"git branch"?在新存储库中保持沉默? [英] Why is "git branch" silent in new repositories?
问题描述
创建新的存储库并运行git branch
时,它会静默退出.例如:
When you create a new repository and run git branch
, it exits silently. For example:
$ mkdir /tmp/foo; cd /tmp/foo; git init
Initialized empty Git repository in /tmp/foo/.git/
$ git branch
该命令为什么不提供任何输出或不显示master分支?
Why doesn't the command provide any output, or show the master branch?
推荐答案
TL; DR
尚无分支头.
TL;DR
No branch heads exist yet.
在您第一次提交之前,Git存储库没有分支.新初始化的存储库将HEAD设置为refs/heads/master,但是在进行第一次提交之前,refs/heads/master不会存在或包含提交指针.
A Git repository has no branches until you make your first commit. A newly-initialized repository sets HEAD to refs/heads/master, but refs/heads/master won't exist or contain a commit pointer until after the first commit is made.
在提交期间,Git取消引用symbolic-ref HEAD来查找当前分支的头,然后使用git-commit-tree提供的提交哈希更新该头.
During a commit, Git dereferences the symbolic-ref HEAD to find the head of the current branch, and then updates that head with the commit hash supplied by git-commit-tree.
最终结果是,git branch
在新存储库中没有任何要报告的内容.没有分支头,它只是以退出状态为零静默终止.
The end result is that git branch
has nothing to report in a new repository. With no branch heads present, it simply terminates silently with an exit status of zero.
- git-branch(1)
- git-commit-tree(1)
- git-symbolic-ref(1).
- git-update-ref(1)
- gitcore-tutorial(7)
这篇关于为什么是"git branch"?在新存储库中保持沉默?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!