Monday 3 July 2017

Git

                                       Git Introduction

It is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency

Having a distributed architecture, Git is an example of a DVCS (hence Distributed Version Control System). Rather than have only one single place for the full version history of the software as is common in once-popular version control systems like CVS or Subversion (also known as SVN), in Git, every developer's working copy of the code is also a repository that can contain the full history of all changes.

Git allows a team of people to work together, all using the same files. And it helps the team cope with the confusion that tends to happen when multiple people are editing the same files.

Using git we can travel to different versions of the files in easy way.
--------------------------------------------------------------------------------------------------------------------------
Creating a directory and making it as git repository using git init command.

[test@server1 ~]$ mkdir g1

[test@server1 ~]$ cd g1

[test@server1 g1]$ git init                      ----> it makes a directory as git repository .

Initialized empty Git repository in /home/test/g1/.git/

------------------------------------------------------------------------------------------

After that first time users should give  Their name and email id to git using  the following way.


[test@server1 g1]$ git config --global user.name "test"             

[test@server1 g1]$ git config --global user.name "test@localhost"


[test@server1 g1]$ ls

[test@server1 g1]$ ls -la

total 12
drwxrwxr-x  3 test test 4096 Mar 28 16:28 .
drwx------ 12 test test 4096 Mar 28 16:28 ..
drwxrwxr-x  7 test test 4096 Mar 28 16:28 .git

------------------------------------------------------------------------------------------

Here we will check how git works by doing a simple example using as below

create a index.html file then add it to  to git repository  to track the file.

[test@server1 g1]$ vi index.html                         ---> creating a file inside git repositry 

[test@server1 g1]$ git add index.html                 ---> add it to repository track it

[test@server1 g1]$ git status             --> This command shows the status of git repository as number of files are in tracking   

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   index.html
#

[test@server1 g1]$ git commit              ---> This command save the changes by give a message and                                                                            commit.
[master (root-commit) c097834] updating
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 index.html

--->It will show the log message as how many log files are there for a file which was commited.

[test@server1 g1]$ git log

commit c097834da5f9f54aa4f08cb253aae41f5557e77b
Author: test <test@localhost>
Date:   Tue Mar 28 16:29:36 2017 +0530

    updating
---------------------------------------------------------------------------
Now change the content of the index file and add to the repository and commit it.by below 

[test@server1 g1]$ vi index.html                           --Change the content 

[test@server1 g1]$ git add index.html


[test@server1 g1]$ git commit -m "update second time"

[master b0e8a8f] update second time
 1 files changed, 2 insertions(+), 0 deletions(-)

-------------------------------------------------------------------------

check the git log to get the previous version file.It will shows the commit id which is help full to go the previous version of the file.

[test@server1 g1]$ git log

commit b0e8a8ffb442dcb86b4cc4481e29e3ab42e256f2
Author: test <test@localhost>
Date:   Tue Mar 28 16:31:29 2017 +0530

    update second time

commit c097834da5f9f54aa4f08cb253aae41f5557e77b

Author: test <test@localhost>
Date:   Tue Mar 28 16:29:36 2017 +0530

    updating

---------------------------------------------------
 get the required modification file using commit id from git log using git checkout command as following

[test@server1 g1]$ more index.html

This is the git file

This is a modification doing second time

-----------------------------------------------------------------------------------------------------------------
Here you can observe that content of index file.

[test@server1 g1]$ git checkout c097834da5f9f54aa4f08cb253aae41f5557e77b -- index.html

[test@server1 g1]$ more index.html

This is the git file

---------------------------------------------------------------------------------------------------------------------
By using the commit id we can travel different versions of the git as below

[test@server1 g1]$ git checkout b0e8a8ffb442dcb86b4cc4481e29e3ab42e256f2 -- index.html

[test@server1 g1]$ more index.html

This is the git file

This is a modification doing second time

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you

Thanks
Devops Desk Team


No comments:

Post a Comment