Cloude Devops Logo Free Clss Will start on Devops from July 15th
Cloud DevOps
Cloud DevOps

Git commit

DevOps Tutorial

Git commit

  1. Definition" Definition
  2. Howitworks" How it works
  3. Options" Common options
  4. Savingchanges" Saving changes with a commit
  5. Howtoupdate" How to update (amend) a commit
  6. commitvsSVN" Git commit vs SVN commit
  7. Snapshots" Snapshots, not differences


The git commit command saves all currently staged changes of the project. Commits are created to capture the current state of a project. Committed snapshots are considered safe versions of a project because Git asks before changing them. Before running git commit command, git add command is used to promote changes to the project that will be then stored in a commit.

How it works

Git snapshots are committed to the local repository. Git creates an opportunity to gather the commits in the local repository, rather than making a change and commit it immediately to the central repository. This has many advantages splitting up a feature into commits, grouping the related commits, and cleaning up local history before committing it to the central repository. This also gives the developers an opportunity to work in an isolated manner.

Common options

git commit -a Commits a snapshot of all changes in the working directory. Only modifications to tracked files are included.
git commit -m "commit message" Creates a commit with a passed commit message. By default, git commit opens the locally configured text editor causing a commit message to be entered.
git commit -am "commit message" Combines the -a and -m options for creating a commit for all the staged changes and taking an inline commit message.
git commit --amend Modifies the last commit. Staged changes are added to the previous commit. This command opens the system's configured text editor and changes the previously specified commit message.

Saving changes with a commit

In the following example,

# touch cloud_devops.txt
DevOps Tutorial we have the cloud_devops.txt file with changed content on the current branch. To commit the staged snapshot of the file, first, you should stage the file with git add command. DevOps Tutorial
git add cloud_devops.txt
DevOps Tutorial

Running git add will move cloud_devops.txt file to the Git staging area. Use the git status command to see the output.

git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: cloud_devops.txt

The green output indicates that cloud_devops.txt will be saved with the next commit. The commit is created by executing:

DevOps Tutorial git commit DevOps Tutorial

Running git commit opens a text editor (we can set it via git config) asking for a commit log message and a list of what is being committed:

# Enter the commit message of your changes. Lines that start
# with '#' will be ignored, an empty message breaks off the commit.
# On branch master
# Changes needed to be committed:
# (use "git reset HEAD ..." to unstage)
#modified: cloud_devops.txt

DevOps Tutorial

The canonical format of Git is used for summarizing the whole commit on the first line in less than 50 characters, then it leaves a blank line, after which gives a detailed explanation of the changes. For example:

Change the message displayed by cloud_devops.txt

- Update the sayHello() function to get the username
- Change the sayGoodbye() function to a more welcoming message

The first line in the commit message is the subject line, the rest is its body.

How to update (amend) a commit

The following example opens the configured text editor pre-filled with the already entered commit message. It means you are editing the last commit instead of creating a new one.

DevOps Tutorial git add cloud_devops.txt DevOps Tutorial

git commit --amend

Git commit vs svn commit

SVN is a centralized application model while Git is a distributed application model. SVN commit pushes changes from the local client to a centralized repository. In Git the snapshots are committed to the local repository. Git commits can be pushed to arbitrary remote repositories.

Snapshots, not differences

Git is based on the snapshots whereas SVN tracks differences of a file. svn commit consists of a diff which is compared to the original file added to the repository. Git records the whole content of all the files in every commit. When committing or saving the state of the project, Git takes a snapshot of the current file look and stores a reference to that snapshot. If there is no change in the file, Git doesn’t store it again.

DevOps TutorialDevOps Tutorial

The DevOps seminar will help you to learn DevOps from scracth to deep knowledge of various DevOps tools such as fallowing List.

Linux, Git, Jenkins, Maven, Apache Tomcat, Nexus, Ansible, Chef, MySQL Docker, Nagios,   Kubernetes.
Continue to Next