Last active
November 26, 2022 08:02
-
-
Save RaviPabari/ca96a0150738d8dfa083d452875b1684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Removing the last commit | |
To remove the last commit from git, you can simply run git reset --hard HEAD^ | |
If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. | |
You can increase the number to remove even more commits. | |
If you want to "uncommit" the commits, but keep the changes around for reworking, | |
remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, | |
but leave the working tree around. | |
If you want to save the commits on a new branch name, | |
then run git branch newbranchname before doing the git reset. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment