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
fatal: Not a valid object name: 'master'
提问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 init
a folder it doesn't create a master branch
当我
git init
创建一个文件夹时,它不会创建主分支
This is true, and expected behaviour. Git will not create a master
branch until you commit something.
这是真实的,也是预期的行为。master
在您提交某些内容之前,Git 不会创建分支。
When I do
git --bare init
it creates the files.
当我这样做时,
git --bare init
它会创建文件。
A non-bare git init
will also create the same files, in a hidden .git
directory in the root of your project.
非裸git init
也会.git
在项目根目录的隐藏目录中创建相同的文件。
When I type
git branch master
it 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 add
them to prepare a commit. Then git commit
to create your initial commit and master
branch.
你还没有提出问题,但我会回答我认为你想问的问题。将一个或多个文件添加到您的目录中,并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 branch
command is not useful).
首先,当您创建一个“裸存储库”时,您不会对其进行任何工作(它不包含工作副本,因此该git branch
命令没有用)。
Now, the reason you wouldn't have a master
branch even after doing a git init
is that there are no commits: when you create your first commit, you will then have a master
branch.
现在,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
- 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).
- You need to commit then everything will work just fine.
- 确保您位于正确的目录中(有时我们会在彼此内部得到 2 个具有相同名称的文件夹,可能不在服务器中,但我曾经有过)。
- 您需要提交,然后一切都会正常进行。