Last week take an another git presentation about git blame

git blame - Show what revision and author last modified each line of a file.

here i am create a simple program for adding two numbers,

after git add and git commit the file, just type git blame <file name> we get the below details.

^bca6360 (xyz 2019-01-31 12:08:12 +0530 1) num1 = input('Enter first number:')
^bca6360 (xyz 2019-01-31 12:08:12 +0530 2) num2 = input('Enter second Number: ')
18ec7bc8 (abc 2019-01-31 12:14:03 +0530 3) 
ce863009 (xyz 2019-01-31 12:21:56 +0530 4) sum = float(num1) + float(num2)
7e2b4892 (xyz 2019-01-31 12:18:45 +0530 5) 
ad5c1d56 (xyz 2019-02-04 12:32:57 +0530 6) print ('the sum of {0} and {1} is {2}'.format(num1, num2, sum))

her we can see the code in line by line and also see the which user is modified with date and time.

now just edit the file,

for example just add a print command after line number 4 we get like this..

^bca6360 (xyz 2019-01-31 12:08:12 +0530 1) num1 = input('Enter first number:')
^bca6360 (xyz 2019-01-31 12:08:12 +0530 2) num2 = input('Enter second Number: ')
18ec7bc8 (abc 2019-01-31 12:14:03 +0530 3) 
ce863009 (xyz 2019-01-31 12:21:56 +0530 4) sum = float(num1) + float(num2)
95545467 (xyz 2019-02-04 12:37:57 +0530 5) print ('sum is')
7e2b4892 (xyz 2019-01-31 12:18:45 +0530 6) 
ad5c1d56 (xyz 2019-02-04 12:32:57 +0530 7) print ('the sum of {0} and {1} is {2}'.format(num1, num2, sum))

Here we can see total 7 lines (before total lines is 6) and in 5th line shows an extra print command.

95545467 (xyz 2019-02-04 12:37:57 +0530 5) print ('sum is')

Here we can see who is edit the file with date and time.

This is the basic use of git blame command in Git.

More About git blame
git blame [<options>] [<rev-opts>] [<rev>] [--] <file>

while we change the option we can see more about the file.

eg: when type below command we can get only 1-3 lines in a program.

git blame -L 1,3 blame.py
^bca6360 (xyz 2019-01-31 12:08:12 +0530 1) num1 = input('Enter first number:')
^bca6360 (xyz 2019-01-31 12:08:12 +0530 2) num2 = input('Enter second Number: ')
18ec7bc8 (abc 2019-01-31 12:14:03 +0530 3) 
:$ git blame -e blame.py
^bca6360 (<xyz@gmail> 2019-01-31 12:08:12 +0530 1) num1 = input('Enter first number:')
^bca6360 (<xyz@gmail> 2019-01-31 12:08:12 +0530 2) num2 = input('Enter second Number: ')
18ec7bc8 (<abc@gmail> 2019-01-31 12:14:03 +0530 3) 
ce863009 (<xyz@gmail> 2019-01-31 12:21:56 +0530 4) sum = float(num1) + float(num2)
95545467 (<xyz@gmail> 2019-02-04 12:37:57 +0530 5) print ('sum is')
7e2b4892 (<xyz@gmail> 2019-01-31 12:18:45 +0530 6) 
ad5c1d56 (<xyz@gmail> 2019-02-04 12:32:57 +0530 7) print ('the sum of {0} and {1} is {2}'.format(num1, num2, sum))

-e for get details about the modified user with their gmail.

c:$ git blame -l blame.py
^bca636075bbb165747b33c49f0f038139a08918 (xyz 2019-01-31 12:08:12 +0530 1) num1 = input('Enter first number:')
^bca636075bbb165747b33c49f0f038139a08918 (xyz 2019-01-31 12:08:12 +0530 2) num2 = input('Enter second Number: ')
18ec7bc82335290f4814807d3a85b395f56e300e (abc 2019-01-31 12:14:03 +0530 3) 
ce863009d3c0b58721317a04cf830b8a09a0e0a0 (xyz 2019-01-31 12:21:56 +0530 4) sum = float(num1) + float(num2)
95545467f231f1c72574c82e9c4f7f67a12449b5 (xyz 2019-02-04 12:37:57 +0530 5) print ('sum is')
7e2b489230e1b8095aaf31fd21afe7a290a39057 (xyz 2019-01-31 12:18:45 +0530 6) 
ad5c1d5665baf8aa22241c34310ebe526fec71dc (xyz 2019-02-04 12:32:57 +0530 7) print ('the sum of {0} and {1} is {2}'.format(num1, num2, sum))

-l Show long revision.

-t for show time stamp

etc..

Also this week we learn about python

Python is a powerful high-level, object-oriented programming language created by Guido van Rossum. and we follow the book "Learn Python 3, the hard way" by "ZED A SHOW". also install Python on my pc using the command.,

sudo apt get install python3

and also create some python programs for find largest number in list of numbers and more 5 excise in Python book. and run the program using the command python3 <file name> with this also try git command and add add and commit to git.

Thanks.