GIT致命:模棱两可的说法'HEAD':未知的版本或路径不在工作树中 [英] GIT fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree

查看:7947
本文介绍了GIT致命:模棱两可的说法'HEAD':未知的版本或路径不在工作树中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Debian初始化一个新的GIT repo(实际上是Virtualbox上的一个虚拟机,安装并运行在Mac OS X上):

  [david @ server-VM-001:〜$] mkdir test 
[david @ server-VM-001:〜$] cd test
[david @ server-VM-001: test $] git init
在/home/david/test/.git/
中初始化空的Git仓库fatal:模棱两可的参数'HEAD':未知版本或路径不在工作树中。
使用' - '将路径与版本
分开[david @ server-VM-001:test(master#)$]

有什么问题?

解决方案

正如其他人指出的,来自你的shell提示符。问题是在新创建的仓库 HEAD .git / HEAD )指向一个ref



$ p $ %git init test
在/ Users / jhelwig中初始化的空共享Git存储库/ tmp / test / .git /
%cd test
%cat .git / HEAD
ref:refs / heads / master
%ls -l .git / refs / heads
total 0
%git rev-parse HEAD
HEAD
致命:ambiguous argument'HEAD':未知版本或路径不在工作树中。
使用' - '将路径与修订分离

它看起来像<$ c $正在使用c> rev-parse 时没有进行充分的错误检查。在创建第一个提交之后, .git / refs / heads 看起来有些不同,并且 git rev-parse HEAD 会不再失败。

 %ls -l .git / refs / heads 
total 4
-rw ------- 1 jhelwig staff 14 Oct 14 16:07 master
%git rev-parse HEAD
af0f70f8962f8b88eef679a1854991cb0f337f89

在为我的shell提示符的其余部分(ZSH的wunjo提示主题的重大修改版本)更新Git信息的函数中,我有以下几点来解决这个问题:

  zgit_info_update(){
zgit_info =()

本地gitdir = $(git rev-parse --git-dir 2> / dev / null)
if [$? -ne 0] || [-z$ gitdir];然后
返回
fi

#更多代码...
}


I'm trying to initialize a new GIT repo from Debian (actually a VM on Virtualbox, installed and running on Mac OS X) :

[david@server-VM-001:~ $] mkdir test
[david@server-VM-001:~ $] cd test
[david@server-VM-001:test $] git init
Initialized empty Git repository in /home/david/test/.git/
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
[david@server-VM-001:test  (master #) $] 

What's the problem?

解决方案

As others pointed out, this message is coming from your shell prompt. The problem is that in a freshly created repository HEAD (.git/HEAD) points to a ref that doesn't exist yet.

% git init test
Initialized empty shared Git repository in /Users/jhelwig/tmp/test/.git/
% cd test
% cat .git/HEAD
ref: refs/heads/master
% ls -l .git/refs/heads
total 0
% git rev-parse HEAD
HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

It looks like rev-parse is being used without sufficient error checking before-hand. After the first commit has been created .git/refs/heads looks a bit different and git rev-parse HEAD will no longer fail.

% ls -l .git/refs/heads
total 4
-rw------- 1 jhelwig staff 41 Oct 14 16:07 master
% git rev-parse HEAD
af0f70f8962f8b88eef679a1854991cb0f337f89

In the function that updates the Git information for the rest of my shell prompt (heavily modified version of wunjo prompt theme for ZSH), I have the following to get around this:

zgit_info_update() {
    zgit_info=()

    local gitdir=$(git rev-parse --git-dir 2>/dev/null)
    if [ $? -ne 0 ] || [ -z "$gitdir" ]; then
        return
    fi

    # More code ...
}

这篇关于GIT致命:模棱两可的说法'HEAD':未知的版本或路径不在工作树中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆