How to Undo Various GIT Commands - RobotGirls/FTC-Team-25 GitHub Wiki

Undo GIT merge before GIT push

  • If you do a git merge before you do a git push and you want to undo it, you can do the following
    • Reference: git how to undo merge before push
    • This is the simplest way if you haven't made any new commits after the merge.
      • git merge --abort
    • If you've made commits after the merge, you can use git reset to go back to the state before the merge.
      • git reset --hard HEAD~1
        • HEAD~1 refers to the commit before the most recent one (which is the merge commit in this case).
        • --hard flag discards any uncommitted changes. If you want to keep your uncommitted changes, use --merge or --soft instead.
        • Important:
          • Be cautious with git reset --hard as it completely rewrites history.
          • If you have already pushed the merge, you'll need to use git revert to undo the merge.

How to Compare a Local Git Branch with its Remote Branch

Get out of Detached Head State

  • Reference: Recovering from the GIT Detached HEAD state
  • In Git, the detached HEAD state occurs when the HEAD does not point to a branch, but instead points to a specific commit or the remote repository.
  • If you find yourself a detached HEAD state and realize it right away, you can quickly recover by checking out the previous branch.