Resetting all commits

At one point, for various reasons that seemed perfectly logical at the time, I had several half completed commits, commits that included files that should have been ignored (like config files), and just various things that really made a hash of the history.  I wanted to reset everything, and make sure that the config files didn’t include any passwords, and other information.  It’s not the accepted answer on StackOverflow (it’s the next one down from the accepted answer), but I prefer it, because it allows me to keep separate branches in tact, rather than blowing out everything, including ignored files:

git checkout --orphan newBranch
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master

Reading the discussion on the StackOverflow question is also super helpful; you may find the accepted answer to work better in your situation.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.