I have a git repo with several directories, and a single file, MyFile.ext
.
/
LargeDir1/
LargeDir2/
LargeDir3/
.
.
.
MyFile.ext
I'd like to start a new repo with just MyFile.ext
in it, and keep all the history pertaining to it, but ignore everything else (all the LargeDir
s). How can I do this?
For directories, I've successfully used this answer, but I tried that on a single file, and it doesn't work.
I've also tried this answer, which does delete everything except my file, but it also seems to leave all the history around.
GitHub lets you download one file from a repository. This is a useful feature because it means you do not have to clone or retrieve an entire repository to download a particular file.
Use git fast-export
.
First you export the history of the file to a fast-import stream. Make sure you do this on the master
branch.
cd oldrepo
git fast-export HEAD -- MyFile.ext >../myfile.fi
Then you create a new repo and import.
cd ..
mkdir newrepo
cd newrepo
git init
git fast-import <../myfile.fi
git checkout
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