Why do we use git commit? The git commit command 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.
To commit your code changes in git repo with a message, we have two options to do it as:
1. git commit -m “your commit message here”
2. git commit -am “your commit message here”
Now let us see the difference between both commands.
First clear the terminal screen using the command –
clear
– this command will clear your terminal screen
Now we will check the status of our git repo to make sure if we have changes to be committed using the command –
git status
As we can see we have added a new file and also have some code changes which we can commit.
Let us take a look at first command i.e. git commit -m
Example 1:-
git add . git commit -m "some files changed" git push heroku master
As you can see we have to use “git add .” First in order to include new file in commit and then use “git commit -m” to add message for commit.
Now Let us take a look at first command ie git commit -am
Example 2:-
git commit -am "added a new feature some files changed" git push heroku master
Conclusion:-
The basic difference between both Git commands is:
git commit -m = send log message (don't work without git add ) git commit -am = git add -a + git commit -m git add -A = stages Everything
Read Also:-
Exploring the Power of the the_content() Function in WordPress