Rollback to previous state of app deployment – git
I am currently using Git for deploying app to DigitalOcean VPS server. If something wrong with the deployment or the app broken due to bugs in the new source code. how can i rollback to the previous git commit?
I have found the following link useful but i am confused which command i should use.
How to revert Git repository to a previous commit?
Things i want to achieve:
- I want to rollback to previous state of the app.
- The rollback command should only change my server(DigitalOcean) codebase not the Github repository
- The command can be automated.
I have read few answers about
git checkout which required a commit hash
i.e. 0d1d7fc32. However, This approach required some extra steps and might not be useful for automated script.
Thanks in Advance.
2 Solutions collect form web for “Rollback to previous state of app deployment – git”
If you want to roll back to a previous commit just use:
git checkout HEAD~
HEAD references the current commit
HEAD~ references the previous commit
HEAD~2 references the commit before the previous commit
To re-examine the most recent commit use
git checkout <remote> <branch> which is probably
git checkout origin master. This will effectively reverse the original command.
Ok, so if you want to abandon all the work since your previous commit, the command is:
git reset --hard HEAD~1
The ~1 tells git to rollback to the previous commit. ~2 is the commit before that, and so on (~3, ~4, …).
Doing this will not affect your GitHub repos, unless you push the modifications.
To have this command automated, you can write a script that executes this command on your repository folder.
PS: there are a lot of different ways you can do this. You should choose the option you’re most comfortable with.