Utoljára aktív 1724184521

to go back to a previous commit.

git-oops.md Eredeti

Rogue Coder?

Working on your own passion project and just want it to work? Follow these instructions below, they’ve worked reliably for me for years.

Working with others on a project? Git is complicated. Research and consider other answers, and discuss with your team before you do something rash. And these options are the definition of rash.

Reverting Working Copy to Most Recent Commit

To revert to the previous commit, ignoring any changes:

git reset --hard HEAD

where HEAD is the last commit in your current branch

Reverting The Working Copy to an Older Commit

To revert to a commit that's older than the most recent commit:

# Resets index to former commit; replace '56e05fced' with your commit code
git reset 56e05fced 

# Moves pointer back to previous HEAD
git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

# Updates working copy to reflect the new commit
git reset --hard

# Push your changes to respective branch
git push -f

Credits go to a similar Stack Overflow question, Revert to a commit by a SHA hash in Git?.