将 git stash pop 应用于新的子模块

Apply git stash pop to new submodule

我同时完成了两项任务:编写一些代码并将我的工作树的文件夹作为子模块。当我切换任务时,我只是 git stash save 我修改过的文件。问题是我修改的文件现在是新子模块的一部分。

当我尝试在顶级文件夹上执行 git stash pop 时,我遇到了很多冲突

$ git stash pop
error: refusing to lose untracked file at 'folder/file1'
error: refusing to lose untracked file at 'folder/file2'
[and so on]

CONFLICT (modify/delete): [folder]/file1 deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of [folder]/file1 left in tree. 
CONFLICT (modify/delete): [folder]/file2 deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of [folder]/file2 left in tree. 
[and so on]
CONFLICT (file/directory): There is a directory with name [folder] in Stashed changes. Adding [folder] as [folder]~Updated upstream

其中[文件夹]是前一个folder/new子模块

我对完整的 repo 做了一个干净的克隆,新的子模块没有问题。

有没有办法将存储转移到子模块?或者获取存储中的文件并在子模块中手动合并它们?

我找到了 'hacky' 解决方案。

首先我用 git stash show stash@{0} -p.

从我的藏品中制作了一个 git 补丁

然后我手动编辑补丁来修改我的路径并删除不需要的东西。

然后 git patch mypatch.patch 将更改应用到我的子模块。它在第一次尝试时就成功了,似乎没有任何问题。