How to Commit in GIT

Commit code (make sure to add files first which need to be committed)

git commit -m <message>

Commit code to previous commit

git commit --amend
E.g.
git commit -m 'sample commit'
git add forgotten-file
git commit --amend

Undo Add

git reset

Undo Commit

Undo git commit (changes get unstaged i.e. after modification, we need to re-add, re-commit)
git reset HEAD~
Undo git commit (changes remain staged i.e. after modification, we need to re-commit only) -- useful when we need to change only commit message
git reset --soft HEAD~
Above commands are like moving commit pointer to 1 back position. In case, we want to undo multiple commits, we can use like below
git reset HEAD~3 -> * Undoes 3 commits (changes get unstaged)
git reset --soft HEAD~3 -> * Undoes 3 commits (changes remain staged) 

* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

Leave a Reply

Your email address will not be published. Required fields are marked *