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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9162271/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:55:01  来源:igfitidea点击:

fatal: Not a valid object name: 'master'

git

提问by Roy van Zanten

I have a private server running git 1.7 When I

我有一个运行 git 1.7 的私人服务器当我

git init 

a folder it doesn't create a master branch. Cause when i do:

它不会创建主分支的文件夹。因为当我这样做时:

git branch 

it doesn't list anything. When I do:

它没有列出任何东西。当我做:

git --bare init

it creates the files. When I type

它创建文件。当我打字

git branch master 

it says:

它说:

fatal: Not a valid object name: 'master'.

回答by meagar

When I git inita folder it doesn't create a master branch

当我git init创建一个文件夹时,它不会创建主分支

This is true, and expected behaviour. Git will not create a masterbranch until you commit something.

这是真实的,也是预期的行为。master在您提交某些内容之前,Git 不会创建分支。

When I do git --bare initit creates the files.

当我这样做时,git --bare init它会创建文件。

A non-bare git initwill also create the same files, in a hidden .gitdirectory in the root of your project.

非裸git init也会.git在项目根目录的隐藏目录中创建相同的文件。

When I type git branch masterit says "fatal: Not a valid object name: 'master'"

当我输入时,git branch master它说“致命:不是有效的对象名称:‘主人’”

That is again correct behaviour. Until you commit, there is no masterbranch.

这又是正确的行为。在你提交之前,没有主分支。

You haven't asked a question, but I'll answer the question I assumed you mean to ask. Add one or more files to your directory, and git addthem to prepare a commit. Then git committo create your initial commit and masterbranch.

你还没有提出问题,但我会回答我认为你想问的问题。将一个或多个文件添加到您的目录中,并git add准备提交。然后git commit创建您的初始提交和master分支。

回答by user489998

Git creates a master branch once you've done your first commit. There's nothing to have a branch for if there's no code in the repository.

完成第一次提交后,Git 会创建一个主分支。如果存储库中没有代码,就没有任何分支。

回答by Borealid

First off, when you create a "bare repository", you're not going to be doing any work with it (it doesn't contain a working copy, so the git branchcommand is not useful).

首先,当您创建一个“裸存储库”时,您不会对其进行任何工作(它不包含工作副本,因此该git branch命令没有用)。

Now, the reason you wouldn't have a masterbranch even after doing a git initis that there are no commits: when you create your first commit, you will then have a masterbranch.

现在,master即使在执行 a 之后您也没有分支的原因git init是没有提交:当您创建第一个提交时,您将拥有一个master分支。

回答by Fundhor

You need to commit at least one time on master before creating a new branch.

在创建新分支之前,您需要在 master 上至少提交一次。

回答by Mohammad Elsayed

  1. Make sure that you are in the correct directory (sometimes we get 2 folders inside each other having the same name may be not in servers but I had that once).
  2. You need to commit then everything will work just fine.
  1. 确保您位于正确的目录中(有时我们会在彼此内部得到 2 个具有相同名称的文件夹,可能不在服务器中,但我曾经有过)。
  2. 您需要提交,然后一切都会正常进行。