2012-05-24 101 views
1

我有一个Git子模块,我已经成功克隆到我的主项目中。但是,当我在子模块中进行更改并尝试将其推回原始子模块存储库时,Git拒绝执行此操作。为什么,我该如何解决这个问题?在Git中推子模块更改

例子:我有两个单独的文件夹的子工程和项目超。我把super作为submodule包含在super中。我在文件夹super/sub中进行更改,然后尝试将这些更改推送到原始项目子文件夹中。 Git抱怨。

编辑:关于错误消息,我在Windows上使用Git Bash,很遗憾,无法从终端复制出确切的错误消息。这里是最相关的行:

remote: error: refusing to update checked out branch: refs/heads/master. By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent with what you pushed, and will require 'git reset --hard' to match the work tree to HEAD.

注意:这两个存储库住在我的硬盘上。

+1

这是什么混帐说什么? – Stefan

+0

@Stefan,见编辑。 – astay13

回答

4

这有什么好做的回购是一个子模块。

你推着一个工作副本(非裸回购)的git仓库,并试图推送到当前签出的同一分支 - 默认情况下,git不会让你这样做。

继续你应该问自己,如果你真的想这样做之前。这很类似,比方说,你直接克隆一个同事的回购,然后试图推动它。如果您成功了,可能会导致您的同事在未提交更改的情况下放松工作,或者当更新时使用跟踪文件覆盖本地文件。

简单的解决方案

最简单的方法是在所有不推,从其他的回购只是拉来代替。最终的结果是一样的,但是因为你正在更新内容(这很简单),git不会对此做任何说明。

略少,简单的解决方案

可以推到你其他的工作副本,如果你改变了接收的回购协议的混帐配置(读取错误消息的其余部分),以允许其推入。要做到这一点,在接受回购:

git config receive.denyCurrentBranch ignore 

更多细节大约是在帮助(git config --help

receive.denyCurrentBranch 
    If set to true or "refuse", git-receive-pack will deny a ref update to the 
    currently checked out branch of a non-bare repository. Such a push is potentially 
    dangerous because it brings the HEAD out of sync with the index and working tree. 
    If set to "warn", print a warning of such a push to stderr, but allow the push to 
    proceed. If set to false or "ignore", allow such pushes with no message. Defaults 
    to "refuse". 
+0

请参阅上面的编辑错误消息摘要。 – astay13

+0

谢谢!这有很大的意义,我现在正在发生什么。 – astay13