6.6 Undoing Changes

Hindsight is 20/20, or so they say. Working with your code is no exception. You commit a change and then realize it had a password in it that you shouldn’t be sharing.

In a centralized repository where every change is sent back to a main repository, you are almost out of luck. There are some hoops you can jump through if you have administrator access, but it might well corrupt data.

Git plans for this type of mistake, however. All your changes happen locally and are shared only when you push them to a public repository. Since you’re the only one who has to stay in sync, you can rewrite your history as much as you want!

Dangers of Rewriting History

Before we start, a word of caution: be careful how you use the commands ...

Get Pragmatic Version Control Using Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.