git log 并在裸仓库上显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6214711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git log and show on a bare repo
提问by Graslandpinguin
I created a bare repository on a file-server in my local network at home. After this i pushed a branch of an existing repository from my desktop-pc to this new remote repository.
我在家里本地网络的文件服务器上创建了一个裸存储库。在此之后,我将现有存储库的一个分支从我的台式机推送到这个新的远程存储库。
Pushing worked perfectly and it seems, that all data arrived (a "git branch -va" gives me the correct data). But i cannot use git log or git show on the bare repository. i get an:
推送工作完美,似乎所有数据都到达了(“git branch -va”给了我正确的数据)。但是我不能在裸存储库上使用 git log 或 git show 。我得到一个:
fatal: bad default revision 'HEAD'
fatal: bad default revision 'HEAD'
or simply no output
或者干脆没有输出
is this normal for bare repositories? Is there another possibility to visualize everything?
这对于裸存储库来说是正常的吗?是否有另一种可能性来可视化一切?
Edit: The fatal error is solved now, but i receive no output from "git log" or "git log unstable". Same command on the desktop-pc works perfectly
编辑:致命错误现已解决,但我没有收到“git log”或“git log 不稳定”的输出。桌面电脑上的相同命令完美运行
回答by Richard Hansen
Yes, this is normal for new bare (and non-bare) repositories.
是的,这对于新的裸(和非裸)存储库来说是正常的。
Explanation
解释
HEAD
is what Git calls a symbolic reference—a reference to another reference.
HEAD
就是 Git 所说的符号引用——对另一个引用的引用。
In non-bare repositories, HEAD
normally indicates which branch is currently checked out. A new commit will cause the branch named by HEAD
to be advanced to refer to the new commit. When HEAD
refers to a commit object directly instead of a branch, it's considered to be detached, meaning further commits will not cause a branch reference to be advanced to refer to the new commits (dangerous because checking out a different commit or branch will render the new commits unreachable by any existing reference, making them hard to find and subject to garbage collection).
在非裸存储库中,HEAD
通常指示当前检出哪个分支。新提交将导致名为 by 的分支HEAD
被提前引用新提交。当HEAD
直接引用提交对象而不是分支时,它被认为是detached,这意味着进一步的提交不会导致分支引用被提前以引用新的提交(危险,因为检查不同的提交或分支将呈现新的提交)提交无法被任何现有引用访问,使它们难以找到并受到垃圾收集)。
In bare repositories, HEAD
indicates the repository's default branch, so that in a clone of the repository git checkout origin
is equivalent to git checkout origin/master
if master
is the default branch (see git help rev-parse
for details).
在裸存储库中,HEAD
表示存储库的默认分支,因此在存储库的克隆中git checkout origin
相当于git checkout origin/master
ifmaster
是默认分支(git help rev-parse
详情请参阅)。
When Git initializes a new repository, it initializes HEAD
to refer to refs/heads/master
(in other words, HEAD
points to the master
branch by default). However, it does not create a branch named master
because there are no commits in the repository for master
to point to yet.
当 Git 初始化一个新的仓库时,它初始化HEAD
为引用refs/heads/master
(换句话说,默认HEAD
指向master
分支)。但是,它不会创建一个名为的分支,master
因为存储库master
中还没有指向指向的提交。
So until you either create a master
branch or change HEAD
to point to a branch that does exist, you'll get that error when you run a command that looks at HEAD
(such as git log
or git show
without any arguments).
因此,在您创建master
分支或更改HEAD
为指向确实存在的分支之前,当您运行查看HEAD
(例如git log
或git show
不带任何参数)的命令时,您将收到该错误。
You can still use commands that don't examine HEAD
. For example:
您仍然可以使用不检查HEAD
. 例如:
git log some_branch_that_exists
Fix
使固定
To get rid of the error message, you can do one of the following:
要消除错误消息,您可以执行以下操作之一:
Change
HEAD
to point to a branch that does exist:git symbolic-ref HEAD refs/heads/some_other_branch
- Push a new
master
branch into the repository from somewhere else Create a new
master
branch locally:git branch master some_existing_commit
更改
HEAD
为指向确实存在的分支:git symbolic-ref HEAD refs/heads/some_other_branch
master
从其他地方将新分支推送到存储库中master
在本地新建一个分支:git branch master some_existing_commit
Visualization
可视化
To visualize everything in the repository, I use something like this:
为了可视化存储库中的所有内容,我使用以下内容:
git log --graph --oneline --date-order --decorate --color --all
Note that the above command will work even if HEAD
is pointing to a non-existent branch.
请注意,即使HEAD
指向不存在的分支,上述命令也将起作用。
回答by VonC
Note that this message will change with Git 2.6 (Q3/Q4 2015)
请注意,此消息将随 Git 2.6(2015 年第 3 季度/第 4 季度)发生变化
See commit ce11360(29 Aug 2015) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit 699a0f3, 02 Sep 2015)
请参阅Jeff King ( )提交的 ce11360(2015 年 8 月 29 日)。(由Junio C Hamano合并-- --在提交 699a0f3,2015 年 9 月 2 日)peff
gitster
Finally, that message will be more meaningful:
最后,该消息将更有意义:
log
: diagnose emptyHEAD
more clearlyIf you init or clone an empty repository, the initial message from running "
git log
" is not very friendly:
log
:HEAD
更清楚地诊断空如果您初始化或克隆一个空存储库,则运行“
git log
”的初始消息不是很友好:
$ git init
Initialized empty Git repository in /home/peff/foo/.git/
$ git log
fatal: bad default revision 'HEAD'
Let's detect this situation and write a more friendly message:
让我们检测这种情况并写一个更友好的消息:
$ git log
fatal: your current branch 'master' does not have any commits yet
We also detect the case that 'HEAD' points to a broken ref; this should be even less common, but is easy to see.
Note that we do not diagnose all possible cases. We rely onresolve_ref
, which means we do not get information about complex cases. E.g., "--default master
" would usedwim_ref
to find "refs/heads/master
", but we notice only that "master
" does not exist.
Similarly, a complex sha1 expression like "--default HEAD^2
" will not resolve as a ref.But that's OK. We fall back to a generic error message in those cases, and they are unlikely to be used anyway.
Catching an empty or broken "HEAD" improves the common case, and the other cases are not regressed.
我们还检测到“HEAD”指向损坏的引用的情况;这应该更不常见,但很容易看到。
请注意,我们不会诊断所有可能的情况。我们依赖resolve_ref
,这意味着我们无法获得有关复杂案例的信息。例如,"--default master
" 将用于dwim_ref
查找 "refs/heads/master
",但我们只注意到 "master
" 不存在。
类似地,像“--default HEAD^2
”这样的复杂 sha1 表达式不会解析为 ref。不过没关系。在这些情况下,我们退回到通用错误消息,无论如何都不太可能使用它们。
捕获一个空的或损坏的“HEAD”会改善常见情况,而其他情况不会回归。
回答by ?kio
I faced this error when I first pushed to the repo a non-master branch.
当我第一次将非主分支推送到 repo 时,我遇到了这个错误。
To solve the problem, I just had to push master to the repo, and that's it !
为了解决这个问题,我只需要将 master 推送到 repo,就是这样!