Wipe a commit from my local branch

Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

If you want to permanently remove a commit from your branch we can use the git reset feature. Let’s have a look.

Instructor: [00:00] In our local repository here, we have different kind of commits. You can see here, this is the point which has already been synchronized with a remote repository. We have two further commits added on top of them.

[00:13] Let's assume that we committed them, but we changed our mind and we actually want to completely discard them. What we can do is we can copy here the ID of that commit to which we want to return.

[00:25] The important part here is don't return before the things that have been synchronized with the remote repository.

[00:32] We can use the git reset command --hard, and then basically use that commit ID. What will happen, if we execute that, and then do a git log again, is that we will now see that the first two commits have been discarded and we have jumped back to the point to which we have synchronized with the remote repository.

[00:53] Note that the --hard command here also changes your local working directory to make it point to exact the same commit. If you had unsynchronized changes or uncommitted changes still pending in your local workspace, those would be discarded.

[01:09] To avoid that, simply remove that --hard.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today