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.
Adding commits keep track of our progress and changes as we work. git considers every commit change point or "save point". it's a point within the project you'll go back to if you discover a bug, or need to create a change.
When we commit, forever|we must always} always include a message.
By adding clear messages to every commit, it's simple for yourself (and others>
to see what has modified and when.
git commit -m "First release of hi World!"
221ec6e] 1st release of hi World!
three files modified, twenty six insertions(+>
create mode 100644 README.md
create mode 100644 bluestyle.css
create mode 100644 index.html
The commit command performs a commit, and the -m "message" adds a message.
The Staging environment has been committed to our repo, with the message:
"First release of hi World!"
Git Commit without Stage
Sometimes, after you make small changes, using the staging environment sounds like a waste of your time. it's possible to commit changes directly, skipping the staging environment. The -a option can automatically stage each modified, already tracked file.
Let's add a small update to index.html:
<p>This is the first file in my new Git Repo.</p>
<p>A new line in our file!</p>
This is the first go into my new git Repo.
A new line in our file!
And check the status of our repository. however now, we'll use the --short choice to see the changes in a more compact way:
git status --short
Note: Short status flags are:
?? - untracked files
A - Files added to stage
M - modified files
D - Deleted files
We see the file we expected is changed. thus let's commit it directly:
git commit -a -m "Updated index.html with a new line"
[master 09f4acd] Updated index.html with a replacement line
one file changed, one insertion(+>
Warning: Skipping the Staging environment is not usually recommended.
Skipping the stage step will sometimes cause you to include unwanted changes.
Git Commit Log
To view the history of commits for a repository, you'll use the log command:
commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803 (HEAD -> master>
Date: fri Mar 26 09:35:54 2021 +0100
Updated index.html with a new line
Date: fri Mar 26 09:13:07 2021 +0100
1st release of hi World!