Git Commit Command

Git Commit Command

The Git Commit Command used to record the changes in the repository. It is the next command after the git add. Every commit contains the index data and the commit message. Every commit forms a parent-child relationship. When we add a file in Git, it will take place in the staging area. A commit command is used to fetch updates from the staging area to the repository.

The staging and committing are co-related to each other. Staging allows us to continue in making changes to the repository, and when we want to share these changes to the version control system, committing allows us to record these changes.

Commits are the snapshots of the project. Every commit is recorded in the master branch of the repository. We can recall the commits or revert it to the older version. Two different commits will never overwrite because each commit has its own commit-id. This commit-id is a cryptographic number created by SHA (Secure Hash Algorithm) algorithm.

The Git Commit command

The commit command will commit the changes and generate a commit-id. The commit command without any argument will open the default text editor and ask for the commit message. We can specify our commit message in this text editor. It will run as follows:

$ git commit  

The above command will prompt a default editor and ask for a commit message. We have made a change to newfile1.txt and want it to commit it.

Git commit -a:

The commit command also provides -a option to specify some commits. It is used to commit the snapshots of all changes. This option only consider already added files in Git. It will not commit the newly created files. Consider below scenario:

We have made some updates to our already staged file newfile3 and create a file newfile4.txt. Check the status of the repository and run the commit command as follows:

$ git commit -a  

Git commit -m:

The -m option of commit command lets you to write the commit message on the command line. This command will not prompt the text editor. It will run as follows:

$ git commit -m “Commit message.”  

The above command will make a commit with the given commit message.

Git Commit Amend (Change commit message):

The amend option lets us to edit the last commit. If accidentally, we have committed a wrong commit message, then this feature is a savage option for us. It will run as follows:

$ git commit -amend  

The above command will prompt the default text editor and allow us to edit the commit message.

For more Git Related post click here.

  1. Git init Command
  2. Git add Command
  3. Git Clone Command
  4. Git Config Command
  5. Git Alias Command
  6. Git Checkout Command
  7. Git Pull Command
  8. Git Push Command
  9. Git Fetch Command
  10. Git Status Command
  11. Git Revert Command
  12. Git Remove (rm) Command
  13. Git LOG Command