Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (19.4k points)
I have a web server that serves a project that is a git repository. When I do some changes to the code I then do a git pull from the server. Sometimes the new code just crashes, I would like to be able to do a rollback to the latest pull, the one just before. I want to do that with a script, without having to search what is the latest sha. How can I do that?

Edit: Just to clarify, I just want to have to do one action, like pushing a button that says "oops! this latest pull I just did was a mistake, I wish I didn't do that". I don't want to have to look for sha or tags or anything else in this situation, it's more like an 'undo' function. Then I want to be able to continue working on the code and the next pull on the server needs to bring the latest changes.

1 Answer

0 votes
by (27.5k points)

Follow these steps in order to roll back to the state before the previous pull: 

Step 1: See the list of all commits that are or were referenced in your repo at any time.

$ git reflog

Step 2: Pick the commit version from the list to which you want to move back.

Step 3: Execute the following command: 

$ git reset --hard <commit version>

Related questions

+1 vote
1 answer
+3 votes
2 answers
asked Aug 1, 2019 in DevOps and Agile by Han Zhyang (19.7k points)
0 votes
1 answer
+4 votes
1 answer
0 votes
1 answer

Browse Categories

...