How to undo in Git
One of the best parts in version control is undo. This is a quick collection of undo commands in git.
Unstage a staged file
If you staged a file in mistake, you can unstage it using reset HEAD
:
Unmodify a modified file
You made some unsatisfied changes in a file and want to discard it.
You can use checkout --
command:
Change last commit
If you forget to add some files or mess up your commit messages, use --amend
option to edit your last commit:
This command takes your staging area and uses it for the commit.
The amend
commit will replaces your last commit.
Redo last commit
If you made a unwanted commit, you can overwrite it using git reset HEAD^
command like it never happens:
Git Configs
edit ~/.gitconfig
file: