Git: Revert and Reset

Git revert and reset is used to undo changes.

Git revert

  • Create new commit in order to reflect the changes.
  • git revert HEAD means revert to commit before HEAD.
  • Used when the change is already pushed to repository.
  • Reverting merged commit needs an additional flag -m n where n is a number >0.

Git reset

  • Move the HEAD to a specific commit in order to reflect the changes.
  • git reset HEAD means point HEAD to a commit at HEAD, which will do nothing.
  • Used before the change is pushed to repository.

Comments

Leave a Reply

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