Ever faced a situation to cleanup the history in git where you do not need to retain very older commits in history that you never will rollback or do any operation??
I faced this where i need only recent 700 commits in my history.
Here is the work around i did.
Let branch1 be the one which has some 5k+ commits committed years ago
Now i need branch2 with just recent 700 commits in the history, that is the 700th commit from present to past should be the initial one of the repo
I used the fast-export and import feature of git along with the linux sed command combined together for this
git fast-export branch1~700..branch1 | sed “s|refs/heads/branch1|refs/heads/branch2|” | git fast-import
- Use fast-export to export the recent 700 commits in branch1 branch
- sed – way to create a new branch called branch2 out of branch1 branch
- Import the exported 700 commits alone into the branch2 branch
Now you will have your desired branch2 in your local repo which you can push to github