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.

  • Beanstalk initial git deployment
  • How to manage a tiny variation in a git repo over the long term
  • Deploy once a specific branch with capistrano?
  • Deployment using CodeDeploy failing at “install” step due to error “File already exists”
  • Why is Windows Azure's Git Deploy regularly unable to access my repository?
  • Git post-receive hook acts differently to shell
  • 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.

  • Git - Some commits can only be seen in “All Branches” where the only branch is master
  • Collapse a branch down to one commit
  • Azure Cloud Services and Git continuous deployment?
  • Tower can't connect to git (permission denied) when certificate has different name
  • ubuntu server with gitolite password
  • Different actions for different environments
  • 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.

    Git Baby is a git and github fan, let's start git clone.