以前我可以在 git 中推送,但现在不能

问题描述 投票:0回答:2

我克隆了一个带有 url=URL 的存储库,就像文件夹一样:

(git) clone URL folder

下一个: (git) 将此“文件夹”克隆到文件夹中。A y 文件夹。B

下一个:

(git) commit in folder.B

但我不能:

(git) push origin master

因为错误:

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.

我觉得以前成功了(从文件夹.B 推送),但现在不行了。

我正在尝试从folder.B 推送到远程(在本例中为“文件夹”)。

git git-push
2个回答
1
投票

(澄清一下:你提到的第二步是:你跑了

git clone folder folder.A; git clone folder folder.B
,对吗?)


如果我正确理解你的第二步:你从目录

folder.B
工作,它有一个“远程”目录
folder

这工作得很好,你只是偶然发现了该设置中的主要故障:
由于

folder
是一个带有签出分支的存储库(所谓的非裸存储库),因此
git
有一个安全机制来避免修改该文件夹上的活动分支。

解决方法很简单:在

folder/
中,更改活动分支。

git checkout -b someotherbranch

这将允许您从

folder:master
folder.A
推至
folder.B


如果您的目的是在工作站上的多个分支上工作,则更好的工具是使用工作树。

检查

git help worktree


-1
投票

您是否尝试在存储库子文件夹中部署存储库? Git 子模块功能可能会帮助你。检查一下: https://git-scm.com/book/en/v2/Git-Tools-Submodules

© www.soinside.com 2019 - 2024. All rights reserved.