Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Undo a commit that has already been pushed to the remote repository


    If we pushed our changes already to the remote repository we have to pay attention to not change the git history (using commands like rebase, reset, amend etc). Other collaborators of the same repository might already have pulled your changes, thus resulting into horrible, strange merge conflicts if we change the git history. There are some “safer commands” for undoing in such cases.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Let's inspect the log history of the inaudible repository here. You can see here a couple of commits, and all of them have already been synced to the remote counterparts, so to the remote repository.

    If that situation happens and if we want to undo, for instance, that first commit, we have to pay attention to not apply git commands, which actually change the commit IDs in front of here, such as git reset or git amend and so on.

    Rather, what we have to do is to undo this in a safe manner. We can use the git revert command. We pick here the ID we want to revert, which could even be some commit further down here. We hit enter.

    It will then open up in editing mode and tell us, "What kind of commit message would you like to apply?" We can either leave it like this or change it. Let's leave it like this. We save it.

    If we log again, you can see that here a new commit has been created, which is the exact opposite of that commit here.

    Basically, if we added here a couple of lines, this commit will exactly remove those lines that have been added here. Since we have created a new commit message here, we can save to push it after the remote repository.