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?
No. The short answer is NO. It is not possible to rename a file in Git and remember the 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With