Git commit command

Git commit command is the subset of git commands. Commit in version control means, that update the repository with changes you have done on the local copy. So that others have access to the changes/features.  In case of git, the commit command updates the locally cloned copy of the repository, later git push command, updates the central repository.

Git commit command for a new file:

In software development life-cycle, a new resource (e.g new file in the source code ) is always added. First, the git add command is executed to make a file available for the next commit.  Following is an example of adding a new file (called example.c)  in the git repository.

[root@CentOS_6_64-152 my_git_respositorty]#  git add example.c

[root@CentOS_6_64-152 my_git_respositorty]# git commit -m "example.c is added"

To see the commit history

root@CentOS_6_64-152 my_git_respositorty]# git log
commit 0371cf00c44f1ed73b107976a70866eb5c2f62b0
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:12:45 2018 -0500

example.c is added

git commit for modified files:

In software development, the code changes are common. Git provides the way to find out all changes and to commit the changes in the repository,  git status command file lists the changed files. Once a list of changed files is ready. The files are added for next commit with git add command. In this example, a file file1.txt is the change file.

Git list commits:

[root@CentOS_6_64-152 my_git_respositorty]# git status
# On branch master
# Changed but not updated:
# (use “git add <file>…” to update what will be committed)
# (use “git checkout — <file>…” to discard changes in working directory)
#
# modified: file1.txt

Add the file for next commit:

[root@CentOS_6_64-152 my_git_respositorty]# git add file1.txt

Commit again with new list to commit:

[root@CentOS_6_64-152 my_git_respositorty]# git commit -m “Updated files commit”
[master 6e9a7ad] Updated files commit

Verify the commit or git list commits:

[root@CentOS_6_64-152 my_git_respositorty]# git log
commit 6e9a7ad3181bf5d8a627611ad2150bc570878c26
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:26:27 2018 -0500

Updated files commit

commit 0371cf00c44f1ed73b107976a70866eb5c2f62b0
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:12:45 2018 -0500

example.c is added

Git commit all:

When there is list of all files and its ok to commit all files,  git provides option for committing all files without git add.

[root@CentOS_6_64-152 my_git_respositorty]# git commit -a -m “Commit without git add”
[master 88792a1] Commit without git add

Git list commits:

[root@CentOS_6_64-152 my_git_respositorty]# git status
# On branch master
nothing to commit (working directory clean)
[root@CentOS_6_64-152 my_git_respositorty]# git log
commit 88792a16175280aab940c0a65008d8e8682443c0
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:33:23 2018 -0500

Commit without git add

commit a6506b29b55e09ad76378d26336984ce6e63fbea
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:32:02 2018 -0500

New file2

commit 6e9a7ad3181bf5d8a627611ad2150bc570878c26
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:26:27 2018 -0500

Updated files commit

commit 0371cf00c44f1ed73b107976a70866eb5c2f62b0
Author: root <root@CentOS_6_64-152.(none)>
Date: Sun Jan 28 02:12:45 2018 -0500

newfile.c is added

Git remove commit from branch or undo a commit:

The git revert command removes a commit from a branch. The original commit does not remove from history. But a new commit takes place on head of branch to with undo changes.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top