【问题标题】:Strange git error奇怪的 git 错误
【发布时间】:2012-09-05 00:41:56
【问题描述】:

我要做的是,获取 Dropbox 项目的本地克隆,进行更改然后推送到该项目。

我的电脑规格是:Os Win 8 X64,Git-1.7.11

我做了以下步骤:

  1. 将原始项目文件复制到 Dropbox 文件夹中
  2. 在本地文件系统Dropbox文件夹中的项目目录中初始化git repo
  3. 然后通过键入git clone absolute/path/to/the/folder 克隆此目录
  4. 对文件进行了一些更改,只是为了测试,提交..一切顺利
  5. 当我尝试通过键入 git push origin master 来推送此错误消息时

原始 TXT 看起来像这样

$ git push origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 322 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare reposit
remote: error: is denied, because it will make the index and work tree incon
ent
remote: error: with what you pushed, and will require 'git reset --hard' to
h
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variabl

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing

remote: error: its current branch; however, this is not recommended unless y
remote: error: arranged to update its work tree to match what you pushed in

remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour,

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse
To F:\Cloud\Dropbox\Web Server\pcand.me
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'F:\Cloud\Dropbox\Web Server\pcand.me'

尝试完全卸载并清除痕迹并重新安装3次,执行上述步骤2-3次。没有任何帮助

我错过了什么?

【问题讨论】:

  • "默认情况下,在非裸仓库中更新当前分支是被拒绝的"你是如何初始化新仓库的?
  • @PeeHaa 右键单击​​文件夹内-> Git Init(此命令创建隐藏的 .git 文件夹)然后附加此文件夹内的所有文件。
  • 你可以试试git init --bare再试一次吗?
  • @PeeHaa 再次执行所有步骤?还是只是在 Dropbox 项目文件夹中执行此操作?
  • @PeeHaa git init --bare 一定是第一步?

标签: windows git windows-8 dropbox msysgit


【解决方案1】:

通常,推送到非裸存储库不是一个好主意。

我要做的是:

创建一个空目录“/path/to/bare/repository” 输入该目录并执行

git init --bare

这将初始化一个可以安全推入的 git 结构。不要将 Dropbox 文件夹中的任何文件放在那里。

创建一个空目录“/path/to/working/folder”

将Dropbox文件复制到那里,进入目录并输入以下命令

git init
git remote add origin /path/to/bare/repository
git commit -a -m 'Initial commit'
git push origin master

git init 命令没有--bare 参数,因此这将是一个工作文件夹,您可以在其中查看您的文件。将文件推送到“原始”存储库后,检查裸存储库的内容。你不会在那里找到任何可读的文件,只有你的 git 索引。

【讨论】:

  • 不要真的。你能帮我一个忙,通过teamviewer进入我的电脑吗?
  • @epic_syntax:推送到非裸仓库的问题在于它不会更新工作目录,所以东西会变得一团糟。基本上,答案的重点是,有两个回购。一个是裸露的,这就是您将更改推送到的地方。另一个有一个工作目录(即:不是裸的),你去那里并从裸仓库中 pull 以更安全地进行更改。
  • @cHao 我找不到“你在那里找不到任何可读文件,只有你的 git 索引。”是的,我都做了。现在,如果有人从不可读的文件夹中拉出,他会得到正常的内容吗?
  • @epic_syntax:这意味着“这里没什么可看的;继续前进”。该目录仍然可读和可写,并且将包含您推送到它的任何提交。它只是没有相应的工作目录要更新。当有人从中提取时,他们的 git 将有效地检索您的更改并在自己的 repo 上重放它们,并相应地更新自己的工作目录。所以,是的,他们会认为一切正常。
  • @cHao 据我了解,git文件夹和工作目录必须在单独的文件夹中?那么主要项目将如何更新?
猜你喜欢
  • 1970-01-01
  • 2010-10-17
  • 1970-01-01
  • 2010-11-17
  • 1970-01-01
  • 2014-05-08
  • 1970-01-01
  • 2014-10-11
  • 2012-04-27
相关资源
最近更新 更多