📖 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.

Leave a Reply