In this article you will learn about git commit , what is git commit?, how we can delete a last commit and how we can delete some specific git commit.
git-commit - Record changes to the repository:
The git commit
captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to. Prior to the execution of git commit
, The git add
command is used to promote or 'stage' changes to the project that will be stored in a commit. These two commands git commit
and git add
are two of the most frequently used.
How create a new commit the new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it (unless no branch is associated with the working tree
syntax:
git commit -m "commit message"
How to undo last commit
To undo last commit use git reset --hard HEAD~1
git reset command will reset your last commit and checkout at you 2nd last commit of your current working tree. this will resets the current directory to its state in HEAD, and a simple git reset resets everything to its state in HEAD.
How to undo specific commit
Yoy can easily find the commit sha. To find the hash (SHA) id of your any commit Use the git log
command
git reset --hard commitSHA