title: Non-interactive way to squash a range of git commits not starting from HEAD
body: <p>I'm currently working on an iOS project. I have a script which runs when I build. This script updates the build number and commits it into git as well as pushes it. However, after a few days of using it, I realized a side effect. I can have consecutive commits where it is incrementing the build number. So my commit logs are flooded with these commits. This gets particularly exacerbated because the project is broken up into a couple of core libraries. So working on the libs invariably results in a build increment (since it is the same workspace).</p>
  
  <p>What I realize now is that I need a script smart enough to squash consecutive commits which are the update of the build number. </p>
  
  <p>Running </p>
  
  <p><code>git log -20 --pretty=format:"%h - %s"</code></p>
  
  <p>for example, will yield</p>
  
  <pre><code>6add12a1 - Update the package from handle
  70f438be - Updated client version to 0.15.0.2152 and next version to 0.15.0.2153
  7d84151f - Updated client version to 0.15.0.2151 and next version to 0.15.0.2152
  eace113b - Updated client version to 0.15.0.2150 and next version to 0.15.0.2151
  e72624dd - Updated client version to 0.15.0.2149 and next version to 0.15.0.2150
  85d15b6c - Updated client version to 0.15.0.2148 and next version to 0.15.0.2149
  a4e140cd - Updated client version to 0.15.0.2147 and next version to 0.15.0.2148
  ffb18892 - Updated client version to 0.15.0.2146 and next version to 0.15.0.2147
  ebd33432 - Updated client version to 0.15.0.2145 and next version to 0.15.0.2146
  f0727ca7 - Updated client version to 0.15.0.2144 and next version to 0.15.0.2145
  80ab2939 - Adjust balance if FB rewards popup is shown
  0c04a1d7 - Updated client version to 0.15.0.2143 and next version to 0.15.0.2144
  e89fd769 - Updated client version to 0.15.0.2142 and next version to 0.15.0.2143
  c404f9ce - Updated client version to 0.15.0.2141 and next version to 0.15.0.2142
  3911fb31 - Updated client version to 0.15.0.2140 and next version to 0.15.0.2141
  ee3b7056 - Updated client version to 0.15.0.2139 and next version to 0.15.0.2140
  cfb3b2a7 - Updated client version to 0.15.0.2138 and next version to 0.15.0.2139
  a11fa3d9 - Add conditionals compilation to remove some logging
  b9d0f75a - Disable backlight
  ba4447ae - Updated client version to 0.15.0.2137 and next version to 0.15.0.2138
  </code></pre>
  
  <p>So in this example, I'd want to squash down 70f438be to f0727ca7 and then update the commit to be something like "Updated client version from 0.15.0.2138 to 0.15.0.2152". </p>
  
  <p>There are 2 things that need to be done. </p>
  
  <ul>
  <li>Write a script or manually squash consecutive build number increment commits</li>
  <li>Update my script to check if the previous commit(s) is/are build number increments and if so, squash.</li>
  </ul>
  
  <p>I have no issues writing the scripts themselves. Rather the focus of this question is the git command itself. The details about the scripts are provided as context.</p>
  
  <p>What I'm looking for is how to use git non-interactively to squash a specific consecutive range of commits that are not starting at the HEAD. References I've seen thus far have all squashed from the HEAD.</p>
  
  <p>Such as this.</p>
  
  <p><a href="https://stackoverflow.com/questions/7275508/is-there-a-way-to-squash-a-number-of-commits-non-interactively">Is there a way to squash a number of commits non-interactively?</a>.</p>
  
  <p>I will go through that some more later today since it may hold the answer still.</p>
  
  <p>Oh yeah and the clarify, these commits are all pushed already.</p>
  
  <p>Note that this is on a Mac. And the latter script is run from Xcode (Build Phase) and is a Python script using GitPython.</p>