I worked on two tasks at the same time : writing some code and make a folder of my working tree a submodule. When I switched task, I simply git stash save
my modified files. The problem is that my modified files are now part of the new submodule.
And when I try to do a git stash pop
on the top folder, I got a lot of conflicts
$ 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
Where [folder] is the previous folder/new submodule
I did a clean clone of the complete repo and the there is no problem with the new submodule.
Is there a way to transfer the stash to the submodule? Or to get the files in the stash and merge them manually in the submodule?
I found a 'hacky' solution.
First I made a git patch from my stash with git stash show stash@{0} -p
.
Then I manually edited the patch to modify my paths and the remove the unwanted things.
Then git patch mypatch.patch
to apply the changes to my submodule. It worked on first try and seems to build without any trouble.