DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 27

Reverting the Latest Commit in a Git Repository

The Nautilus application development team reported issues with recent changes in the /usr/src/kodekloudrepos/media repository. The DevOps team was tasked with reverting the latest commit and restoring the repository to its previous state, while recording the change with a new commit message.

Steps Performed

  1. Navigate to the repository
cd /usr/src/kodekloudrepos/media
Enter fullscreen mode Exit fullscreen mode
  1. Check commit history
git log --oneline
Enter fullscreen mode Exit fullscreen mode

Output showed:

89baa1d add data.txt file
b67c5f6 initial commit
Enter fullscreen mode Exit fullscreen mode
  1. Revert the latest commit
git revert HEAD --no-edit
Enter fullscreen mode Exit fullscreen mode

This created a revert commit but with the default message Revert "add data.txt file".

  1. Amend the commit message The requirement was to use all lowercase revert media, so the commit was amended:
git commit --amend -m "revert media"
Enter fullscreen mode Exit fullscreen mode
  1. Verify the history
git log --oneline
Enter fullscreen mode Exit fullscreen mode

Final output:

04ee874 revert media
89baa1d add data.txt file
b67c5f6 initial commit
Enter fullscreen mode Exit fullscreen mode

Top comments (0)