Removing the last commit

removing the last commit

Assume you committed your work and didn’t push to remote yet, after some conversation or reading your code you decided to delete or update the last commit you’ve made. Probably, you want to make more changes in your code and then you’ll push your commit.

To undo the last commit we use git reset and there are several options passed to this command. The most common three of them is

$ git reset –hard
$ git reset –mixed
$ git reset –soft

  • When you run the git reset command with option hard, it will undo the last commit as well as delete the all changes you’ve made included in this commit.
  • When you run the git reset command with option soft, it will undo the last commit but preserve all changes you’ve made included in this commit, they’ll stay tracked.
  • When you run the git reset command with option mixed, it will undo the last commit, it’ll preserve the all changes you’ve made included in this commit but they’ll be untracked, you need to stage them again if you want to. It’s also the default operating mode.

Source

Leave a Reply

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