title: Git: Preserving current code state and last four commits
body: <p>PLEASE NOTE: This questions is different to <a href="https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git">Squash my last X commits together using Git</a> as <strong>we are not looking to squash the <em>last</em> X commits together</strong> into a single commit - instead we are looking to <strong>consolidate the <em>initial</em> commits into a single commit and retain the last four commits</strong> / code state in an <strong>automated way</strong> (without having to manually pick commits).</p>
  
  <p>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. </p>
  
  <p>We would like to <strong>consolidate earlier redundant commits</strong> that are no longer required to reduce the size of the repo, but <strong>keep the current code state and the last four commits</strong> as backups in case we need to restore our datastore to a previous commit.</p>
  
  <p>Which commands are recommended within an <strong>automated script</strong> that would change the following git history:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>To become the following <strong>without loosing the current code state</strong>:</p>
  
  <pre><code>4    aabbgg Initial commit -&gt; Fourth backup (consolidated)
  5    aabbhh Fifth backup
  6    aabbii Sixth backup
  7    aabbjj Seventh backup (current code state)
  </code></pre>