User Tools

Site Tools


git:git-back-to-last-commit

Back to git main page

To completely remove the changes and come back to last commit, first get the last commit id (hash)

The full form of the hash (ID) is :

git rev-parse  HEAD

The short form of the ID si :

git rev-parse --short HEAD

We call the ID we get, the COMMIT_ID

A hard (strong) come back with reset to the file state at the last commit. All the uncommitted changes we be lost :

git reset --hard COMMIT_ID

A smoother way is to temporarily stash the uncommitted changes, and add them back after resetting to last commit :

git stash
git reset --hard COMMIT_ID
git stash pop
git/git-back-to-last-commit.txt · Last modified: 2023/03/31 12:17 by 127.0.0.1