This information will stroll you thru the method of restoring your GitHub repository to a particular commit utilizing Git instructions.
Let’s say you’ve gotten a Github repository the place you push all of your code modifications. Every commit has a singular commit hash, and you should utilize this hash to revive the code to a particular commit or a specific time.
It’s advisable that you simply take a backup of your present code earlier than continuing.
Discover the Commit Hash
To get began, open your repository on Github and discover the commit you need to restore. You are able to do this by clicking on the “Commits” tab and discovering the commit within the record. If you wish to restore to a specific date, you should utilize the calendar dropdown to see all of the commits for that day and discover the one you need.
You might also use the command line to search out the commit hash.
After you have discovered the commit you need to restore, you may create a brand new department at that commit. Let’s name this department working-branch
.
git checkout -b working-branch <commit-hash>
This git
command will create a brand new department named working-branch
pointing to the required commit and switches to that department.
Subsequent, you may pressure push the brand new department to the distant repository.
git push -f origin working-branch
Rollback to a Particular Commit
Now that you’ve a brand new department with the code on the particular commit, you may replace the primary department to this restored state.
git checkout essential
git reset --hard working-branch
git push -f origin essential
⚠️ Please watch out when utilizing these git
instructions since it should completely delete all code modifications made after the commit you’re restoring.