What is the opposite of `git filter-branch --subdirectory-filter`?

With git filter-branch --subdirectory-filter you can independently convert the subdirectory from the current repository to the repository. However, I would like to do the following: create a repository that will contain the full contents of the current repository as a subdirectory, preserving the entire history, as if they were always in this subdirectory. I do not want to use submodules because I would like this directory to be a fully integral part of the repository.


Background: I was tasked with writing a simple script, but the task area was expanded, so now the script becomes just a subdirectory in a larger project. It also does not make sense to live as you wish, so a solution without submodules is preferable.

+4
source share
3 answers

The simplest solution is to leave only history: just git mv all your files into a subdirectory, commit this change and continue your life.

If you really want to pretend like you've been working in a subdirectory all the time, the least complicated way is to use something like:

 git filter-branch --tree-filter "mkdir SUBDIR && bash -c 'git mv -k {,.[!.],..[!.]}* SUBDIR/'" 

Replace SUBDIR with the name of the target subdirectory.

+8
source

You can simply transfer the files to the subproject repository in the directory where you would like to have them in the large repository, and then merge these commits into the final repository. This will completely preserve the history of both repositories, including all commit identifiers.

This can be done using commands similar to:

 cd /path/to/subproject mkdir subproject_dir git mv file1 dir2 dir3... subproject_dir git commit cd /path/to/main_project git pull /path/to/subproject 
+2
source

Use the git subtree . Assuming you have a new repo:

 $ cd $ROOT_OF_NEW_REPO $ git subtree add --prefix=subdirectory/for/old/repo <old git repo URL or checkout> <commit ref> 

eg.

 $ git subtree add --prefix=history ~/repos/oldrepo HEAD 

The history directory will contain oldrepo files with the HEAD message along with the entire history.

+1
source

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


All Articles