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

git commit for a new file:

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

[root@CentOS_6_64-152 my_git_respositorty]#  git add newfile.c
[root@CentOS_6_64-152 my_git_respositorty]# git commit -m "newfile.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
newfile.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 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
newfile.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 Reply

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