Reputation: 4097
I have a legacy repository that has been corrupted through some misdirection of LFS and files that are no longer accessible. The result is that it requires access to files that no longer exist to push to a new repository or major surgery on the history that seems too difficult/risky that this time. I would like to attempt to create a new repository and push only recent history to avoid the old and bad commits. Say, all commits since a certain date or from a certain commit. Is this possible?
Upvotes: 4
Views: 230
Reputation: 535201
Why not just delete everything before the first "good" commit?
One easy way:
git rebase -i --root
You are shown a list of all commits in reverse order from the start, e.g.
pick aa48e9c start
pick e10b625 middle
pick 6691860 finished up
Let's say we want to get rid of "start" and "middle" but keep "finished up". So just delete those two lines and save.
pick 6691860 finished up
An artificial empty first commit will be created, but the bad commits will be gone. There might be some conflicts to work out but it shouldn't be difficult.
Upvotes: 2
Reputation: 692
Perhaps you could try git rebase --onto <sha1> <sha2> <sha3>
(see this link) functionality where
So all in all something like this:
newRepo
mkdir newRepo
cd newRepo
git init
newRepo
just to initialize master branchtouch temp_file_for_initial_commit
git add .
git commit -m "Initial commit of new corruption-free repository"
oldRepo
git add origin "/path/to/oldRepo" # notice it could just be a path to the local repo
git fetch origin
git rebase --onto
to copy old range of valid commits to new repogit rebase --onto master <sha of parent of first commit> <sha of latest commit>
git checkout -b latest-history-on-new-repo
git remote remove origin
Upvotes: 0