我是GIT的新手。我一直在阅读/演奏并且非常享受它。
然而,在将克隆的更改推送到主服务器之前,一切都运行良好。
这是我目前的工作流程。
初始化现有应用程序。
cd /var/www/app
git init
git add .
git commit -m "my first"
创建新目录并克隆主目录。
mkdir /var/www/apptest && cd "$_"
git clone /var/www/app .
创建新分支,修改并合并回克隆。
git checkout -b fix
echo "hello" > test.txt
git add test.txt
git commit -a -m "added test file"
git checkout master
git merge fix
一切正常。
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
在这里,所有人都崩溃了,试图将克隆推回主人。
git push origin master
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/var/www/app/'
git push origin/master
fatal: 'origin/master' does not appear to be a git repository
fatal: Could not read from remote repository.
我错过了什么或做错了什么?我读过一些人们说你需要删除原始主人并推送克隆的东西。这看起来很疯狂。
任何帮助都将不胜感激。
答案 0 :(得分:0)
/var/www/app
需要成为一个简单的回购。你不能把它推到一个非裸仓库。
因此,工作流程的开头将是这样的
cd /var/www/app
git init --bare
然后您可以继续完成其余的工作流程。
答案 1 :(得分:0)
评论:将当前仓库称为本地仓库(而非克隆版),并从远程克隆原始仓库,绝对不是主(这是主分支的默认名称)。这些是帮助避免混淆的标准术语。
话虽如此,
问题是远程(app
repo /var/www/app
)有一个工作目录(不是一个裸存储库),并且当前已检出主服务器。以下是我的Git版本(2.13.3.windows.1)中报告的消息:
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
所以有几个选择:
如果您打算将app
repo作为永久远程仓库(即作为多个团队成员的中央仓库或仅作为备份的仓库),则使用{{ 1}}在没有工作目录的情况下初始化它(然后git init --bare
将具有您在apps
中通常会找到的相同内容。这就是为什么大多数人会使用apps/.git
作为文件夹名称的原因一个光鲜的回购。)
以第二种方式创建一个裸仓库 - 这实际上是许多Git服务所需要的(如Github)
apps.git
回购,但实际上并未创建提交app
回购,并提交一些内容apptest
repo添加为远程:app
git remote add origin /var/www/app
使用上面错误消息中的配置变量来忽略这种情况
做一些其他时髦的事情来解决这种情况。
git push origin
,并检查初始提交(使用哈希,而不是app
)。此时,由于master
未签出,您可以从master
推出。当然,最好的解决方案可能是#1(毕竟你只是试图测试Git)。当您在Github等服务上创建中央回购时,他们将仅创建一个裸仓库。