Reading time: 15 minutes
git-commit is a basic git command which saves the staged changes made to your local repository.
At this point, let us edit the rocket.txt file in our project and run the git status command.
We see there are two changes in the project:
- One is not staged
- The other change is staged
At this point, we can add all changes to our staging area by using the git add command, and then run the git commit command to commit this change to our repository.
We see that git status reports that the unstaged change has not been commited.
Now going through these series of steps for multiple changes is nice for organization, but it can be a bit unnecessary for small simple changes such as this one. Now, git provides a shortcut if you want to skip the staging area completely and jump right to committing your changes. You can use this shortcut by typing git commit, and then the -a option. The -a option automatically stages all changes in your working directory that are being tracked by Git, essentially skipping the git add step. In the same command, you can then use the -m option to add a commit message.
If we then run this command, we can see it in the git output that our commit snapshot was successful. Let's now run git status to double check. As you can see, there is nothing to commit, and now our working tree is clean again. Alright, we just made our first two commits.
Git responded with some output to verify that everything was committed successfully. Following is the information provided by git commit command:
Git provides the branch we made the commit on, which in our situation is the master branch.
We see the SHA1 hash from the commit
The commit message that we provided
The number of files that we changed
Statistics on how many insertions and/or deletions that were made in these files for this commit
If a new file was added with this commit, Git shows us that too on the next line that says create mode 100644, which is saying a normal file was created, and then the name of the new file.