你在一个尚未出生的树枝上

xzabzqsa  于 2022-10-23  发布在  Git
关注(0)|答案(9)|浏览(151)

我有一个奇怪的问题:

$ 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)

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

new9mtju

new9mtju1#

一如既往,Git是对的,它只是有一种奇怪的表达方式:当你创建一个存储库时,master分支实际上还不存在,因为它没有什么可指向的。
你有没有试过在下午1点后做些什么?当然,添加遥控器并从中拔出也可以。

hfyxw5xn

hfyxw5xn2#

我和你有同样的问题。我解决的方法是创建一个新的空文件,以便在项目中有一个文件。
git add someFilecommit -m "first commit",最后是push origin master
我希望这会有帮助

ykejflvf

ykejflvf3#

如果有人达到了这一部分,我认为你没有运气得到最好的答案。我和OP也有同样的情况。试试这个:
1.将您的回购放到另一个目录中
1.将.git文件夹复制到新的存储库

rjjhvcjd

rjjhvcjd4#

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

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

如果您碰巧有--bare回购,那么解决方法如下:

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
dtcbnfnu

dtcbnfnu5#

因为你想

git init

在您拥有的根文件夹中。gitignore文件。创建一个子文件夹并在那里尝试。

uajslkp6

uajslkp66#

这是因为您正在上传默认分支为main的git存储库。但在裸存储库上,默认分支master是默认分支。要轻松解决此问题,请删除基本存储库。运行以下命令。
git config --global init.defaultBranch main然后使用以下命令再次创建裸存储库。
git init --bare

toiithl6

toiithl67#

当我打开多个Windows资源管理器时,我收到了相同的错误消息,这两个资源管理器都对同一个现有的本地git repo打开。
我在一个窗口中使用右键单击-->createbranch创建了一个新分支。
后来,在Windows资源管理器的第二个示例中,我尝试右键单击-->Branch(查找当前 checkout 的分支)。然后我收到了一条信息:“你在一个尚未出生的树枝上”。
只需关闭第二个资源管理器就可以解决问题,并且错误不会显示在第一个资源管理程序中。

uqxowvwt

uqxowvwt8#

我遇到了与OP相同的问题。最初,我做了以下操作:

md Project
cd Project
git init
git remote add origin git@domain.com:user/repo.git

所有后续的git命令都有与OP相同的错误。
对我有效的方法是删除Project文件夹,然后从父文件夹发出以下命令:

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

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

git config --global credential.helper wincred

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

tag5nh1u

tag5nh1u9#

尝试在末尾添加分支


# !/bin/bash

TARGET="/home/user/repo"
GIT_DIR="/home/user/www.git"
BRANCH="master"
while read oldrev newrev ref
do
 # only checking out the master (or whatever branch you would like to deploy)
 if [ "$ref" = "refs/heads/$BRANCH" ];
 then
  echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
  git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
 else

  # perform more tasks like migrate and run test, the output of these commands will be shown on the push screen
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
 fi
done

相关问题