30/100 Git Hard Reset
The Nautilus application development team was working on a git repository /usr/src/kodekloudrepos/news
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
.
- In
/usr/src/kodekloudrepos/news
git repository, reset the git commit history so that there are only two commits in the commit history i.einitial commit
andadd data.txt file
. - Also make sure to push your changes.
ssh natasha@ststor01
sudo su -
[root@ststor01 ~]# cd /usr/src/kodekloudrepos/news
[root@ststor01 news]# ls -l
total 8
-rw-r--r-- 1 root root 10 Oct 2 09:43 info.txt
-rw-r--r-- 1 root root 32 Oct 2 09:43 news.txt
[root@ststor01 news]# git log --oneline
9281fb2 (HEAD -> master, origin/master) Test Commit10
c769f59 Test Commit9
f4dafd8 Test Commit8
8ad761d Test Commit7
331c0fc Test Commit6
fb76d55 Test Commit5
07ac5b5 Test Commit4
21c1a95 Test Commit3
cdf2b83 Test Commit2
f7c0e09 Test Commit1
f00e37b add data.txt file
9445144 initial commit
[root@ststor01 news]# git reset --hard f00e37b
HEAD is now at f00e37b add data.txt file
[root@ststor01 news]# git push --force
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /opt/news.git
+ 9281fb2...f00e37b master -> master (forced update)
[root@ststor01 news]# git status
On branch master
Your branch is up to date with 'origin/master'.