Search code examples
gitgit-reset

GIT Reset - How to get back to specific state in repository


I have a list of commits.

abc--most recent
def
ghi
jkl
mno
pqr
stu
vwx

Now I want to remove/forget the changes from abc(most recent commit) to mno. I want to do this in local as well as remote branch (It's a seperate branch, Not master). My aim is to completely move back to the repository version pqr. Don't need backup of any changes after commit pqr.

What is easiest and safest way to avoid any further issues?


Solution

  • If you want to get rid of revisions mno to abc from history:

    git reset --hard pqr
    

    Careful not to have uncommitted changes laying around because they will be busted. This will require you to force-push into the remote branch.

    If you want to keep history then you need a revision after abc to go back to the contents of mno:

    git restore --staged --worktree --source=pqr .
    git commit -m "Getting content back to pqr"