DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 30

Resetting Git History

As part of a cleanup task for the Nautilus application development team, I was asked to reset the Git history of the repository located at /usr/src/kodekloudrepos/games on the Storage server in Stratos DC.

This repository had several test commits made by developers, but the goal was to clean it up and retain only two commits:

  • initial commit
  • add data.txt file

Steps I Took

Navigated to the repository:

   cd /usr/src/kodekloudrepos/games
Enter fullscreen mode Exit fullscreen mode

Checked the commit history to identify the commit hash for add data.txt file:

   sudo git log --oneline
Enter fullscreen mode Exit fullscreen mode

I confirmed that the commit hash was: 6aea5f3.
Reset the repository to that commit using a hard reset:

   sudo git reset --hard 6aea5f3
Enter fullscreen mode Exit fullscreen mode

Force pushed the reset state to the remote repository:

   sudo git push origin master --force
Enter fullscreen mode Exit fullscreen mode

Outcome

The Git history was successfully cleaned up. The repository now contains only the following two commits:

  • initial commit
  • add data.txt file

This meets the requirement of cleaning the repository and removing all test commits from history, both locally and on the remote.

Top comments (0)