【问题标题】:Not a valid object name: 'master'不是有效的对象名称:'master'
【发布时间】:2016-04-20 09:13:06
【问题描述】:

我在其中创建了新目录 testCD
在其中创建新的存储库:

git init

创建一个文本文件 test.txt 和一个目录,其中包含另一个文本文件 mydir/newfile.txt

echo "Hello" > test.txt 
mkdir mydir
echo "hello" > mydir/newfile.txt
git add test.txt
git add mydir/newfile.txt
git commit

在这些步骤之后,当我想通过写作来建立一个分支时:

git branch new_branch

我有错误:

致命:不是有效的对象名称:'master'

【问题讨论】:

  • 我怀疑您的存储库中没有任何提交。 git log 显示什么?
  • 致命:你当前的分支'master'还没有任何提交

标签: git git-branch git-bash


【解决方案1】:

试试这个

git commit -m "initial commit"

git push -u origin

它会起作用的。如果您遇到任何问题,请分享您的错误,以便我们找到问题并帮助您。

【讨论】:

    【解决方案2】:

    谢谢大家。
    我只需要通过这两行定义我的电子邮件和用户名,一切正常:

    $ git config --global user.name "username"  
    $ git config --global user.email "example@example.com"
    

    【讨论】:

      【解决方案3】:

      我运行的命令和你一样。你可以输入

      而不是 git commit
      git commit -m "Initial check-in"
      

      然后,将设置该主分支。然后,您可以输入“git branch new_branch”,它会按预期工作。

      它对你不起作用的原因是 git commit 对你不起作用,因此没有设置初始分支。如果你想使用“git commit”,那么在里面输入一些信息。之后,它也应该可以工作了。

      【讨论】:

      • 我也收到了同样的信息。没什么不同。
      猜你喜欢
      • 1970-01-01
      • 2016-08-03
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多