Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

A git feature commit squashing approach

03 May 2021 🔖 git
💬 EN

This is a trick that Ramon Snir taught me to transform a git-tracked feature branch with hundreds of commits (which I’ve already pushed to a GitHub-hosted remote) into looking like it never had anything but a single commit with a message of “Meaningful fake first commit message.”

  1. git checkout the-feature-branch && git reset --hard origin/the-feature-branch
    • This resets your local branch to what’s currently on GitHub
  2. git merge origin/main && git reset --soft origin/main
    • This makes your Git staging area include your branch’s content, but your Git base commit be main
    • Note that this does not pull in actual changes from the remote main that have happened since you started working on the feature branch.
  3. git commit -m "Meaningful fake first commit message"
  4. git log ^origin/main HEAD to verify
  5. git show HEAD to see that you’re pleased with the result
  6. git push --force only if you’re happy with everything from the previous steps
    • This should be the last operation because it’s more-or-less irreversible

If you’re on Windows, your ordinary command line interface (CLI) won’t recognize the &&s in these commands, so instead use the Git Bash CLI tool that came with this version of Git you likely installed, because it uses a mini-Unix-like CLI called MinGW.

--- ---