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:
In /usr/src/kodekloudrepos/ecommerce git repository, reset the git commit history so that there are only two commits in the commit history i.e initial commit and add data.txt file.
Also make sure to push your changes.
Log into storage server and move into repository
sudo -i
cd /usr/src/kodekloudrepos/ecommerce
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
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
Push the changes
git push --force
--soft - Move HEAD, keep staging and working directory--mixed (default) - Move HEAD, reset staging, keep working--hard - Reset everything to specified commit--keep - Reset but keep uncommitted changesgit reflog shows recent HEAD movementsgit reset --hard HEAD@{n} to restoregit gc can remove unreachable commits