Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract git subdirectory while keeping history WITH renames

I'm splitting a big source tree into two separate components and a shared submodule. In order to prepare for this split, I first moved the shared stuff into a single "common" directory, updated all the references, and made a commit. So far so good. Now I'd like to extract that directory into a submodule.

Normally I'd do this with

git filter-branch --subdirectory-filter

But in this case, all the interesting history happened outside that subdirectory, so the history gets lost.

I understand that it doesn't make sense to keep the full history, since that wouldn't be filtering out any data at all. But I'm not really going for the ability to go back in time and build, I just want to be able to look at the commits each file was a member of.

Is there a way to keep the filter-branch behavior while keeping the history of the individual files?

like image 637
Russell Mull Avatar asked Mar 09 '11 08:03

Russell Mull


People also ask

How do I rename a directory in git without losing history?

No. The short answer is NO. It is not possible to rename a file in Git and remember the history.

How do I move files and keep my git history?

In order to solve this, we use git mv command. git mv helps us to rename or move files without deleting their previous history.

How do I see my entire git history?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.


1 Answers

Not really. --subdirectory-filter is a bit of a special case in that it's actually modifying the contents of trees significantly (since it's moving things up one or more directory nesting levels).

As such, there's not really a good mapping between files that are outside of the subdirectory you're filtering on and trees that could be stored as part of commits in the result.

Remember that filter-branch is completely rewriting your history - the output is an entirely new set of commits, and there aren't any "linkages" to the old commits, so any extra information has to be expressible as part of the new commits.

like image 171
Amber Avatar answered Sep 19 '22 18:09

Amber