git 你在尚未出生的树枝上

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

You are on a branch yet to be born

git

提问by Deep

Im have strange problem:

我有奇怪的问题:

$ cd ~/htdocs

$ mkdir test

$ cd test

$ git init
Initialized empty Git repository in /home/deep/htdocs/test/.git/

$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

$ git checkout -b master
fatal: You are on a branch yet to be born

$ git checkout origin/master
error: pathspec 'origin/master' did not match any file(s) known to git.

$ git branch -a
(empty this)

But this is new local empty repo. Where is master branch?

但这是新的本地空仓库。主分支在哪里?

回答by Wander Nauta

As ever, Git is right, it just has a quirky way of saying it: when you create a repository, the master branch actually doesn't exist yet because there's nothing for it to point to.

一如既往,Git 是对的,它只是有一种奇怪的说法:当你创建一个存储库时,主分支实际上还不存在,因为它没有任何指向。

Have you tried committing something after your git init? Adding a remote and pulling from it will also work, of course.

你有没有试过在你之后提交一些东西git init?当然,添加遥控器并从中拉出也可以。

回答by Yorsh

I had the same problem as you. The way I solved was creating a new empty file just to have a file in the project.

我和你有同样的问题。我解决的方法是创建一个新的空文件只是为了在项目中有一个文件。

git add someFilethen commit -m "first commit"and finally with push origin master

git add someFile然后commit -m "first commit"和最后push origin master

i hope it helps

我希望它有帮助

回答by Febrinanda Endriz Pratama

If someone reaches this part, I think you have no luck with the top answers. I got the same situation with OP too. Try this:

如果有人到达这一部分,我认为您对最佳答案不走运。我也遇到了与 OP 相同的情况。尝试这个:

  1. Pull your repo in another directory
  2. copy .git folder to your new repo
  1. 将你的 repo 拉到另一个目录中
  2. 将 .git 文件夹复制到你的新仓库

回答by Stoinov

There is a way to initialize a new repo without actually committing any files:

有一种方法可以在不实际提交任何文件的情况下初始化新的 repo:

git commit --allow-empty -m "Initialization"

If you happen to have --barerepo, then the workaround is as this:

如果你碰巧有--barerepo,那么解决方法是这样的:

mkdir /tmp/empty_directory
git --work-tree=/tmp/empty_directory checkout --orphan master
git --work-tree=/tmp/empty_directory commit --allow-empty -m "Initialization"
rm -rf /tmp/empty_directory

回答by James L.

I had the same issue as the OP. Initially, I did the following:

我和 OP 有同样的问题。最初,我做了以下工作:

md Project
cd Project
git init
git remote add origin [email protected]:user/repo.git

All subsequent gitcommands had the same errors as the OP.

所有后续git命令都具有与 OP 相同的错误。

What worked for me was to delete the Project folder, and then issue the following command from the parent folder:

对我有用的是删除项目文件夹,然后从父文件夹发出以下命令:

git clone http[s]://domain.com/user/repo.git Project

It then prompted me for my username and password to access the repo. Every gitcommand asked for credentials, so I ran the following command:

然后它提示我输入我的用户名和密码来访问 repo。每个git命令都要求提供凭据,因此我运行了以下命令:

git config --global credential.helper wincred

The next gitcommand asked for my credentials, which were then stored in the Windows Credential Manager(visible via the Control Panel). Now gitcommands work without prompting for credentials.

下一个git命令要求提供我的凭据,然后将这些凭据存储在Windows 凭据管理器中(通过控制面板可见)。现在git命令可以在不提示输入凭据的情况下工作。

回答by sboggs11

I had the same error message when I had multiple Windows Explorers open, both opened to the same existing local git repo.

当我打开多个 Windows 资源管理器时,我收到了相同的错误消息,它们都打开到同一个现有的本地 git 存储库。

I created a new branch in one window, by using right-click --> create branch.

我在一个窗口中创建了一个新分支,方法是使用右键单击 --> 创建分支。

Later, in the 2nd instance of Windows Explorer, I attempted to right click --> Branch (to find out which branch was currently checked out). I then got the message "You are on a branch yet to be born".

后来,在 Windows 资源管理器的第二个实例中,我尝试右键单击 --> 分支(以找出当前检出哪个分支)。然后我收到消息“你在一个尚未出生的分支上”。

Simply closing the 2nd Explorer ended the problem, and the error did not show up in the 1st Explorer.

只需关闭第二个资源管理器即可解决问题,并且错误没有出现在第一个资源管理器中。