Git Rebase: Drop Commits But Keep the Files

📖 1 minute read

Ever need to clean up your Git history but keep the files locally? Here’s a trick I used recently.

I had a commit that added some temp markdown docs — useful for my WIP but not ready for the branch history. I wanted those files to stay local (untracked) while removing the commit entirely.

The solution: interactive rebase with the drop command:

git rebase -i <commit-before-the-one-you-want-to-drop>
# In the editor, change 'pick' to 'drop' for that commit
# Save and exit

The commit disappears from history, and the files become untracked. If you accidentally lose them, recover from reflog:

git show <dropped-commit-hash>:path/to/file > path/to/file

Be careful: this rewrites history. Use git push --force-with-lease when ready. Always stash current work first as a safety net.

Daryle De Silva

VP of Technology

11+ years building and scaling web applications. Writing about what I learn in the trenches.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *