Member-only story

Git/GitHub 1- Reverting our repository to an old commit on both GitHub and the Local repository.

In our project where we use GitHub as the repository, after doing “git push”, something didn’t sometimes work properly and we want to revert to an old commit the project was working on. In this article, we will see how to revert the commit in both the local repository and the GitHub repository and return our project to the last working state. In order to achieve this, we will use the following Git Commands in our article: “git log” “git revert” “git checkout” “git reset” “git push -u origin” “git merge” commands step by step.

Cumhur M. Akkaya
5 min readAug 26, 2023

We often use git when developing a project. And we create commits to record and track our progress. Sometimes, an error was made in the last commit, and sometimes an undesired transaction was made.

The last state of our project in GitHub and Local repository can be seen in the Figures 1–2. After pushing the “azure-pipeline.yaml” files, our project did not work properly. We want to remove them and revert to a commit where our project is running.

Figures 1- Local repository
Figures 2- GitHub repository

Firstly, let’s learn how to revert the last commit where the project was working on.

We use the “git log” command to see the commits we have made. We want to revert to commit 4bd3f3abf4c15cec4c468c742ded5544ffd5d4f2, as shown in Figure 3. Because we are sure that our app codes work there.

Note-1: Press Enter to continue the operation on the screen, press Q to exit from git log screen.

Note-2: You can also use the following command for a better output.

--

--

Cumhur M. Akkaya
Cumhur M. Akkaya

Written by Cumhur M. Akkaya

✦ Multi-Cloud & DevOps Engineer, ✦Technical Writer, ✦AWS Community Builder, ✦LinkedInTop Voice, ✦Believes in learning by doing, ✦ linkedin.com/in/cumhurakkaya

No responses yet

Write a response