Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Last active August 8, 2016 18:49
Show Gist options
  • Select an option

  • Save mizanRahman/37474150ca1054db1a5a96aa0baf844c to your computer and use it in GitHub Desktop.

Select an option

Save mizanRahman/37474150ca1054db1a5a96aa0baf844c to your computer and use it in GitHub Desktop.
Git | Undoing Changes

I want to wipe out my local changes that are not committed yet:

  1. wipe out all uncommitted changes that made:

    git checkout .

  2. But it will not wipe out new files that were not committed yet. to remove all uncommitted changes including newly created files:

    git stash
    git stash drop
    

I have commited my changes, Now I want to undo those:

  1. if change is already committed but commit is not pushed yet, reset can be used.

    git reset HEAD

  2. in case of multiple commits: for example if you want to remove last 3 commits

    git reset HEAD~3

I have committed and pushed my changes, now I want to rollback

  1. if change is pushed to remote, revert is good choice.

    git revert <commit>

    it will make a new commit undoing changes in .

  2. to revert last 5 commits:

    git revert HEAD~5

I want to rollback a merge/pull

  1. You merged/pulled a branch, now want to undo that. If you did not pushed your changes to remote, you are a somewhat lucky. you can just reset to your previous commit. git reset HEAD~1

  2. If you have merged and pushed to remote server already, but now you want to undo that. you can revert the merge commit. All you have to do is specify the merge commit you want to revert and the parent line you want to keep.

    git revert -m 1 <commit>

@mizanRahman

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment