Git – Revert to specific commit as a new commit


The git revert command undos one specific commit. It will add a new commit which is the opposite of the commit being undone. If you added a line, it will remove a line. If you removed a line, it will add a line.

If you need to revert to a specific commit so that the state of your repository is exactly as it was at that commit, follow this advice from StackOverflow.

# reset the index to the desired tree
git reset 56e05fced

# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s