PUBLIC.INTERNET

Git Panic Button

A dropdown lists ten common Git mistakes. Choosing one shows a short explanation, a block of commands you can copy, and a warning that says whether the fix is safe or destroys work. The ten cases cover a commit on the wrong branch, undoing the last commit with or without its changes, a wrong commit message, a bad push, merge conflicts, detached HEAD, a deleted file, discarding local changes, and stashing. The answers are fixed text, not read from your repository, so check them against your own branch names and state.

How to use the fix lookup

  1. Open What went wrong? and choose the closest match, such as I committed to the wrong branch or I'm in detached HEAD state.
  2. Read the explanation above the Commands to Run box and the warning below it. Two warnings start with DANGER (undo and delete, discard all changes), but the wrong-branch recipe also runs git reset --hard without that label, so check every block for --hard or clean.
  3. Replace the placeholders, such as new-branch-name or the file name and commit hash, with your own values.
  4. Click Copy and paste into your terminal, but run the lines one at a time. Some blocks, like the merge conflict one, list alternative options, and you want only one of them.

Soft reset, hard reset, and revert: which one loses work

git reset --soft HEAD~1 moves the branch back one commit and leaves your changes staged, so nothing is lost. git reset --hard HEAD~1 does the same move and then resets the index and working tree too. The dropped commit stays reachable through git reflog for a while, but uncommitted edits are gone for good. That is why the wrong-branch recipe (create a branch, then hard reset the old one) is only safe when your working tree is clean. Commit or stash first if it is not.

Once a commit is pushed to a shared branch, rewriting history is the risky route. Amending a message and force pushing, or resetting and force pushing, changes commits other people may already have. git revert HEAD is the shared-branch answer: it adds a new commit that undoes the old one and leaves history intact. The tool's amend recipe uses --force-with-lease, which refuses to overwrite the remote if it holds commits you have not fetched.

A revert does not remove a leaked secret from history, because the old commit is still there. Rotate the credential first, then ask your Git host how to purge the commit. The same caution applies to git clean -fd in the discard recipe: it deletes untracked files, and Git has no record of them to bring back.