PLEASE NOTE: This questions is different to Squash my last X commits together using Git as we are not looking to squash the last X commits together into a single commit - instead we are looking to consolidate the initial commits into a single commit and retain the last four commits / code state in an automated way (without having to manually pick commits).
We are using git to backup / record changes to a file datastore using an internally hosted GitLab server with a repository that contains some very large files.
We would like to consolidate earlier redundant commits that are no longer required to reduce the size of the repo, but keep the current code state and the last four commits as backups in case we need to restore our datastore to a previous commit.
Which commands are recommended within an automated script that would change the following git history:
0 aabbcc Initial commit
1 aabbdd First backup
2 aabbee Second backup
3 aabbff Third backup
4 aabbgg Fourth backup
5 aabbhh Fifth backup
6 aabbii Sixth backup
7 aabbjj Seventh backup (current code state)
To become the following without loosing the current code state:
4 aabbgg Initial commit -> Fourth backup (consolidated)
5 aabbhh Fifth backup
6 aabbii Sixth backup
7 aabbjj Seventh backup (current code state)