pjg*_*ing 25 git xcode macos-catalina
我正在尝试使用命令行将现有项目添加到 GitHub。我在终端的相关工作目录中,正在尝试使用该git init -b main
命令。
最初,我收到与 xcode 相关的错误:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Run Code Online (Sandbox Code Playgroud)
我尝试过,xcode-select --install
但更新服务器上的软件不可用,所以我从https://developer.apple.com/download/more/下载了“Xcode 12 的命令行工具” 。
现在进入git init -b main
我得到以下信息:
error: unknown switch `b'
usage: git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [<directory>]
--template <template-directory>
directory from which templates will be used
--bare create a bare repository
--shared[=<permissions>]
specify that the git repository is to be shared amongst several users
-q, --quiet be quiet
--separate-git-dir <gitdir>
separate git dir from working tree
Run Code Online (Sandbox Code Playgroud)
我正在运行 git 版本:2.24.3 (Apple Git-128)
非常感谢任何帮助!
phd*_*phd 22
git
2.24没有选项-b
/ --initial-branch
。它是在git
2.28中添加的。您需要升级才能使用该选项。
或者,正如@matt 所说,创建一个 repo,然后重命名分支:
git init repo
cd repo
git branch -m master slave
Run Code Online (Sandbox Code Playgroud)
Adr*_*oto 16
如果您需要安装最新git
版本(在 Ubuntu 中)
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
Run Code Online (Sandbox Code Playgroud)
参考: https: //gist.github.com/YuMS/6d7639480b17523f6f01490f285da509
Thi*_*ser 15
该-b
标志仅在 2.28 或更高版本中可用,您需要升级您的 Git。
在基于 debian 的 Linux 系统(如 Ubuntu)上,执行以下操作:
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update
sudo apt install git -y
Run Code Online (Sandbox Code Playgroud)
Rob*_*ade 10
git init # ?
git symbolic-ref HEAD refs/heads/main # ?
Run Code Online (Sandbox Code Playgroud)
? 之后git init
,分支master
实际上并不存在。只有在至少有一次提交时才会创建分支。
? 这更新.git/HEAD
为包含ref: refs/heads/main
而不是ref: refs/heads/master
. 或者,git checkout -b main
。
正如@phd 所说,该-b/--initial-branch
选项是在 git v2.28 中添加的。git 2.28 还引入了一个配置选项来指定您首选的默认分支:
git config --global init.defaultBranch main
Run Code Online (Sandbox Code Playgroud)
init.defaultBranch
在GitHub 的博客文章 中了解有关新设置的更多信息。