DEV Community

Cover image for 5.Git Revert Some Changes
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

5.Git Revert Some Changes

Lab Information

The Nautilus application development team was working on a git repository /usr/src/kodekloudrepos/news present on Storage server in Stratos DC. However, they reported an issue with the recent commits being pushed to this repo. They have asked the DevOps team to revert repo HEAD to last commit. Below are more details about the task:

In /usr/src/kodekloudrepos/news git repository, revert the latest commit ( HEAD ) to the previous commit (JFYI the previous commit hash should be with initial commit message ).

Use revert news message (please use all small letters for commit message) for the new revert commit.
Enter fullscreen mode Exit fullscreen mode

Lab Solutions

Step-by-Step Solution

  1. Login to Storage Server
ssh natasha@ststor01.stratos.xfusioncorp.com
# password: Bl@kW
Enter fullscreen mode Exit fullscreen mode
  1. Switch to root
sudo su -
# password: Bl@kW
Enter fullscreen mode Exit fullscreen mode
  1. Go to the news repository
cd /usr/src/kodekloudrepos/news
git status
Enter fullscreen mode Exit fullscreen mode
  1. Check commit history (to confirm HEAD)
git log --oneline --max-count=2
Enter fullscreen mode Exit fullscreen mode

Example output:

abc1234 Latest commit message
def5678 initial commit

๐Ÿ‘‰ abc1234 = HEAD (latest commit)
๐Ÿ‘‰ def5678 = previous commit (initial commit)

  1. Revert the latest commit
# Run:
git revert HEAD
Enter fullscreen mode Exit fullscreen mode

This will open an editor.

  1. Set the commit message

Replace everything with exactly:

revert news

Save and exit the editor.

โš ๏ธ Commit message must be all lowercase
โš ๏ธ Do NOT add anything else

  1. Verify the revert commit
git log --oneline --max-count=3
Enter fullscreen mode Exit fullscreen mode

You should now see:

revert news
abc1234 Latest commit message
def5678 initial commit


Resources & Next Steps
๐Ÿ“ฆ Full Code Repository: KodeKloud Learning Labs
๐Ÿ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
๐Ÿ’ฌ Join Discussion: DEV Community - Share your thoughts and questions
๐Ÿ’ผ Let's Connect: LinkedIn - I'd love to connect with you

Credits
โ€ข All labs are from: KodeKloud
โ€ข I sincerely appreciate your provision of these valuable resources.

Top comments (0)