I'm using git flow for my projects. When a release has been merged into the master branch it is tagged with the release version (e.g. 1.2.0) and deployed to my production servers.
Now I want to quickly revert to the previous release tag (e.g. 1.1.0) as the deployment should not have happened.
Elaboration:
How would I do this?
Returning to an Old Revision. The fastest way to restore an old version is to use the "reset" command: $ git reset --hard 0ad5a7a6. This will rewind your HEAD branch to the specified version. All commits that came after this version are effectively undone; your project is exactly as it was at that point in time.
The net effect of the git revert command is similar to reset, but its approach is different. Where the reset command moves the branch pointer back in the chain (typically) to "undo" changes, the revert command adds a new commit at the end of the chain to "cancel" changes. The effect is most easily seen by looking at Figure 1 again.
Committing little and often, so that your change history is clear should save you from having to take this route. Whichever option you use, take a note of the ID of the commit you want to revert to. Use git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .
Using a version control system like Git brings a fantastic benefit: you can return to any old version of your project at any time. No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Assuming you want to keep the history, but undo the changes the 1.2.0 release did. Use git-revert to create a new commit that reverts everything 1.2.0 did:
git checkout master
git revert HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With