Using git reset --soft, Marking a commit so that you can squash *down* to it later
<p>Looking to squash commits, so that a publicly facing project doesn't have meaningless commit messages like "temp" or "temp123".</p>

<p>I am looking for a way to use <code>git reset --soft HEAD~5</code>, but instead of randomly picking the number 5, I want to go back through the Git logs and find all the the commits that do not match a pattern, and once I hit the pattern I stop. So let's say my <code>git log</code> commit messages look like:</p>

<pre><code>temp123
fooGit
temp
fml
temp24
tmp69
tttoday
publish/release:xyz
</code></pre>

<p>so I would squash the top 7 most recent commits, but leave everything "below" <code>publish/release:xyz</code>.</p>

<p>For fairly complicated reasons, <code>git merge --squash</code> issued from the public facing branch won't work for me because I am end up deleting or renaming files quite a bit in a project on the private branch and so there are just too many merge conflicts. It seems to me, after trying it several ways, that it's best to push to the public facing branch with -f, and not worry about conflicts in that way.</p>

<p>I think the better approach in my case is to squash commits like so:</p>

<pre><code># on private "dev" branch
# make a bunch of changes, rename files, yadda yadda
git add . &amp;&amp; git add -A &amp;&amp; git commit -am "temp" &amp;&amp;
git checkout -b squash_branch  # we do squashing on this branch to be safer
git reset --soft head~15 # apparently this undoes commits for the last 15 commits
git commit -am "A serious commit message"
git push -u public master -f  # overwrite public master
</code></pre>

<p>this way, I never have to resolve conflicts between the public facing branch and the private development branch, which can be super pointless and annoying from my experience.</p>

<p>However, the problem I am trying to solve has to do with the number 15 above. I am simply just guessing about how many commits to "squash". I would rather know the exact number to squash.</p>

<p>Perhaps I can do a squash of all commits that do not have a Git commit message that fits a certain pattern? So when I run the squash, I create a commit message with a certain pattern, let's say it's "XYZ". Could I run <code>git reset --soft HEAD~(some git commit pattern matching to find the count)</code>?</p>

<p>Also one more question. After doing the squash (<code>git reset --soft</code>) on the <code>squash_branch</code>, should I merge that branch back into the private <code>dev</code> branch?</p>