Before picking specific tools (commands), please pick what you need rather than blindly running commands.
Amending the commit
- Just in case you want to edit your last commit, there is a command.
Just in case you want to edit your last commit, there is a command.
- Advantage: It allows you to correct the last commit's message as well as add more changes to it.
Advantage: It allows you to correct the last commit's message as well as add more changes to it.
git commit --amend
git commit --amend Resetting the Commit
Really want to undo the last commit (because of massive changes or you want to discard it all).
Advantage: The reset command will return to the one before the current revision, effectively making the last commit undone.
A-. Soft Reset
Advantage: -softA soft flag. It guarantees the preservation of modifications made in undone revisions. The changes appear in your working copy as uncommitted local modifications once you run the command.
git reset --soft HEAD~1 git reset --soft HEAD~1 B-. Hard Reset
Advantage: If you don't want to keep these changes, simply use the --hard flag. Be sure to only do this when you're sure you don't need these changes anymore.
git reset --hard HEAD~1 git reset --hard HEAD~1 Undo last commit but keep changes made to the files
Advantage:
This command will tell Git to advance the HEAD pointer back one commit. The files' modifications won't be impacted, though. Now, if you run git status, you ought to still be able to view the local file changes.
git reset HEAD~1 git reset HEAD~1 Use according to your needs.