To undo/remote a commit from a local repository.
Use git show
and git log
to view all commits/code versions to decide what to roll back to.
There are two flags to have a good understanding of - --soft
and --hard
.
--soft
will ensure changes in the version being rolled back to are preserved. This method might be used if a commit was made that included a file that shouldn't have been, but you want to keep all changes that were made.
--hard
will completely revert the working copy to whichever version defined in the command. All changes that occurred after the commit being reverted to will be lost.
git reset --soft HEAD~1
Resetting a remote repository like this is generally a very bad idea as it will break the repository history for any downstream users.
Use the rebase manual as a better reference to this topic.
To undo/remote a commit from a remote repository.
Use git show
and git log
to view all commits/code versions to decide what to roll back to.
Run the reset to the commit you desire.
git reset --hard HEAD~4
Push the reset to the remote repo
git push push --force