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:
fatal: bad default revision 'HEAD'
or simply no output
is this normal for bare repositories? Is there anot开发者_JAVA百科her 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
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.
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).
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).
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.
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).
You can still use commands that don't examine HEAD
. For example:
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
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.
Note that this message will change with Git 2.6 (Q3/Q4 2015)
See commit ce11360 (29 Aug 2015) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit 699a0f3, 02 Sep 2015)
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:
$ 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.
I faced this error when I first pushed to the repo a non-master branch.
To solve the problem, I just had to push master to the repo, and that's it !
精彩评论