Git: Convert Subdirectory to Submodule

I was able to successfully convert submodules into subdirectories using commands such as the methods described in these two examples:

Submodule-> Subdir

Subdir-> Submodule

The challenge is to successfully achieve this in the directory, preserving your history through each conversion .
The two methods described above worked fine on a trivial experimental repository, but did not handle a more complex repository. for example, a repo with an arbitrary commit pattern.

The problem occurs when running

git filter-branch --subdirectory-filter <lib-directory> -- --all

when trying to convert a directory (previously a submodule) to a submodule. If I understand correctly. It darted:

 Rewrite c95281d27e4602e9af50146eefcf7c28f5bb4f35 (2/11)a989b207d3757f9803fd50fa2d77908a4dc1330e fatal: failed to unpack tree object c95281d27e4602e9af50146eefcf7c28f5bb4f35:lib/test_submodule Could not initialize the index` 

of which there were absolutely no similar results on the Internet.
It was found out that this is due to the repeated reference to the submodule in INDEX, as a result of which, when the submodule was converted, the error above occurred.

Is there a way to do filter-branch that avoids these early submodule references ??

Edit: I looked at this problem again, and I still have not found a way to solve it. Using the Subdir-> Submodule method with git filter-branch works fine for a regular directory; but crash when hit the submodule. The crash that continues to occur in this section in git:

https://github.com/github/git-msysgit/blob/master/git-filter-branch.sh#L300

I can’t interpret this, though.

+6
source share
2 answers

For me, this worked after adding a trailing slash to the directory:

 $ git filter-branch --subdirectory-filter htdocs/typo3_src -- --all Rewrite cbe03e13da071403a2632263f1760b560398cdd3 (1/12) (0 seconds passed, remaining 0 predicted) 004b20fc15023539484c7f5990b99780f54dc0ac fatal: failed to unpack tree object cbe03e13da071403a2632263f1760b560398cdd3:htdocs/typo3_src Could not initialize the index $ git filter-branch --subdirectory-filter htdocs/typo3_src/ -- --all Rewrite ec6e3c7212f1080fc052c87b1129335ab5bee524 (5/10) (1 seconds passed, remaining 1 predicted) Ref 'refs/heads/master' was rewritten Ref 'refs/remotes/origin/master' was rewritten Ref 'refs/remotes/origin/develop' was rewritten WARNING: Ref 'refs/remotes/origin/master' is unchanged WARNING: Ref 'refs/tags/0.0.1' is unchanged 
+9
source

Instead of using the rev-list - all option, try filtering with commit hashing.

 git filter-branch --subdirectory-filter <lib-directory> <hash>... 

The end that caused the problem in my case was the one that contains the Subproject commit . Example:

 git filter-branch --subdirectory-filter <lib-directory> c95281d27e4... 
0
source

Source: https://habr.com/ru/post/987504/


All Articles