【问题标题】:Git Workflow 101. I don't get it [duplicate]Git Workflow 101.我不明白[重复]
【发布时间】:2021-09-21 07:53:31
【问题描述】:

我没有找到任何示例显示如何在 git 中完成最简单的任务。

有人可以告诉我执行此 SVN 作业所需的 git 命令吗?

svn checkout svn://jeeves/testrepo
cd testrepo
echo >newfile.txt Wow I added a file
svn add newfile.txt
svn commit -m "How simple was that"

假设我坐在带有 git 存储库的机器上。这就是我正在做的事情(似乎还有数百种变化)。

git clone ~/git/testrepo.git
cd testrepo
echo >newfile.txt Wow I added a file
git add newfile.txt
git commit -m "So far, so good. Everything has worked so far..."
git push origin master

我不敢相信这如此困难。我显然错过了一些东西,因为我不断收到类似的消息

jeeves:~/git/myCare geoffrey$ git push origin master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
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.

救命!

【问题讨论】:

  • 问题是testrepo.git 没有正确设置为允许推送的“服务器”存储库。相反,您已经克隆了一些已签出代码的存储库
  • 您要么设置服务器存储库;或进入 testrepo 并从您的副本中提取。 stackoverflow.com/a/31590993/1505939 完整示例

标签: git


【解决方案1】:

原因:您正在推送到 Non-Bare 存储库

有两种类型的存储库:bare and non-bare

裸存储库没有工作副本,您可以推送到它们。这些是您在 Github 中获得的存储库类型!如果你想创建一个裸仓库,你可以使用

git init --bare

好吧,您不能推送到当前已签出的存储库分支。使用裸存储库,您可以推送到任何分支,因为没有一个被签出。尽管可能,但推送到非裸存储库并不常见。您可以做的是从其他存储库中获取和合并。这就是您可以在 Github 中看到的 pull request 的工作原理。你要求他们从你身上拉开,而不是强行推入他们。


在最新的 git 版本中pushing to the checked out branch of a non-bare repository is possible。尽管如此,您仍然无法推送到 工作树,这无论如何都不是安全操作。

【讨论】:

  • 原来的 testrepo.git 是从 subversion 导入的。那个旧的 subversion 存储库确实已签出工作副本。这可能是问题吗?从那以后,我发现其他 SO Q 似乎有几十个步骤来克隆 SVN 存储库,而我所做的只是一个命令。我将删除 testrepo.git 并尝试遵循更好的指南。谢谢。
猜你喜欢
  • 2016-02-29
  • 1970-01-01
  • 1970-01-01
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
  • 2012-01-28
  • 2021-06-28
相关资源
最近更新 更多