0

我目前正在使用一个最近为了封闭源而被分解的存储库 - 模块已从“主要”存储库移到他们自己的存储库中。

panel/
    file.a
    file.b
    module1/ [untracked by panel repository, instead tracked in own repository now]
        templates/
            base.html
            ...
        views.py

但是,在此分解之前仍有工作已提交,当时module1存储库仍是panel. 我的问题是处理分手前后的提交 - 我目前正在尝试cherry-pick提交对两者中的文件进行更改,panel以及module1在两个存储库都属于panel. (目录结构没有改变,只有git's view of the repositories)

当我在主存储库的目录中挑选时:

nasonfish@nasonfish ~/P/P/p/panel2> git cherry-pick 8b7316d1ebff49e95a7971f88e669f50d9cbbf86
error: refusing to lose untracked file at 'panel/module1/views.py'
error: refusing to lose untracked file at 'panel/module1/templates/module1/view-hdr.html'
error: refusing to lose untracked file at 'panel/module1/templates/module1/view-base.html'
error: refusing to lose untracked file at 'panel/module1/templates/module1/base.html'
error: could not apply 8b7316d... mybranch: This is my commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

我可以看到我不希望将存储库中的文件删除或添加到主存储库,因为这只会撤消分离并合并存储库 - 但我正在尝试将提交的cherry-pick应用程序提交给两个文件中的文件基本和子存储库,而不合并两者。那么,有没有一种方法可以强制 git 以某种方式让单独的嵌套存储库中的文件成为主存储库的一部分,从而允许从存储库分离之前挑选提交?

4

1 回答 1

0

在考虑了如何在不考虑其存储库的情况下将某个提交应用于文件之后,我的目光转向生成要应用的补丁。

我首先发现了如何从提交哈希创建补丁

git format-patch -1 8b7316d1ebff49e95a7971f88e669f50d9cbbf86

然后我使用了我的补丁git apply(因为我不能肯定补丁会与我所拥有的完美合并,所以我应用了--reject开关以合并我可以合并的内容并转储对手动合并不起作用的内容):

git apply 0001-permissions-Add-a-new-user-permissions-system-that-c.patch --reject

然后,我在我的存储库中搜索.rej包含我必须手动合并的补丁的文件,并使用这些文件将更改应用到它们打算合并到的文件中。

在那之后,我知道我已经在我的存储库中应用了更改,我可以简单地将目录更改为每个存储库并使用git commit来指示我已合并的内容。

于 2014-05-24T23:09:37.203 回答