簡體   English   中英

你在尚未誕生的樹枝上

[英]You are on a branch yet to be born

我有一個奇怪的問題:

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

但這是新的本地空倉庫。 主分支在哪里?

一如既往,Git 是對的,它只是有一種古怪的說法:當你創建一個存儲庫時,主分支實際上還不存在,因為它沒有任何指向。

你有沒有試過在你的git init之后提交一些東西? 當然,添加遙控器並從中拉出也可以。

我和你有同樣的問題。 我解決的方法是創建一個新的空文件只是為了在項目中有一個文件。

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

我希望它有幫助

如果有人到達這一部分,我認為您對最佳答案不走運。 我也遇到了與 OP 相同的情況。 嘗試這個:

  1. 將你的 repo 拉到另一個目錄中
  2. 將 .git 文件夾復制到你的新倉庫

有一種方法可以在不實際提交任何文件的情況下初始化新的 repo:

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

如果您碰巧有--bare repo,則解決方法如下:

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

那是因為你想

git init

在您擁有.gitignore文件的根文件夾中。 創建一個子文件夾並在那里嘗試。

當我打開多個 Windows 資源管理器時,我收到了相同的錯誤消息,它們都打開到同一個現有的本地 git 存儲庫。

我在一個窗口中創建了一個新分支,方法是使用右鍵單擊 --> 創建分支。

后來,在 Windows 資源管理器的第二個實例中,我嘗試右鍵單擊 --> 分支(以找出當前檢出哪個分支)。 然后我收到消息“你在一個尚未出生的分支上”。

只需關閉第二個資源管理器即可解決問題,並且錯誤沒有出現在第一個資源管理器中。

我和 OP 有同樣的問題。 最初,我做了以下工作:

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

所有后續的git命令都有與 OP 相同的錯誤。

對我有用的是刪除項目文件夾,然后從父文件夾發出以下命令:

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

然后它提示我輸入我的用戶名和密碼來訪問 repo。 每個git命令都要求提供憑據,因此我運行了以下命令:

git config --global credential.helper wincred

下一個git命令要求提供我的憑據,然后將這些憑據存儲在Windows 憑據管理器中(通過控制面板可見)。 現在git命令無需提示輸入憑據即可工作。

這是因為您正在上傳具有main作為默認分支的 git 存儲庫。 但是在裸存儲庫上,默認分支master是默認分支。 要以簡單的方式解決此問題,請刪除基礎存儲庫。 運行以下命令。
git config --global init.defaultBranch main然后使用以下命令再次創建裸倉庫。
git init --bare

嘗試在最后添加分支

#!/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM