100-Days-Of-DevOps-Challenge-KodeKloud

Git Reset Hard

The Nautilus application development team was working on a git repository /usr/src/kodekloudrepos/ecommerce present on Storage server in Stratos DC. This was just a test repository and one of the developers just pushed a couple of changes for testing, but now they want to clean this repository along with the commit history/work tree, so they want to point back the HEAD and the branch itself to a commit with message add data.txt file. Find below more details:

Steps

  1. Log into storage server and move into repository

     sudo -i
     cd /usr/src/kodekloudrepos/ecommerce
    
  2. Let’s check commits history

     git log --oneline
    
     [root@ststor01 ecommerce]# git log --oneline
     81e08fc (HEAD -> master, origin/master) Test Commit10
     686cb01 Test Commit9
     f0ff119 Test Commit8
     a8404ed Test Commit7
     a9fccf0 Test Commit6
     2554746 Test Commit5
     461c467 Test Commit4
     287d981 Test Commit3
     a63283d Test Commit2
     5479bcb Test Commit1
     90b2925 add data.txt file
     848a423 initial commit
    
  3. Let’s reset the commit history to old one

     git reset --hard 90b2925
    
     root@ststor01 ecommerce]# git status
     On branch master
     Your branch is behind 'origin/master' by 10 commits, and can be fast-forwarded.
     (use "git pull" to update your local branch)
    
     nothing to commit, working tree clean
    
  4. Push the changes

     git push --force
    

Good to Know?

Git Reset Types

Reset Dangers

Safe Alternatives

Recovery Options