
The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.
The git log command will display the history of commits in all of the branches of the cloned repository.
commit mks910122020slsmm3lsosos020399489sl
Author: John Doe <john.doe@example.com>
Date: Wed May 31 14:51:14 2020 -0500
updated LDAP queries to include Active Directory (AD)
commit dkci85474fjfdkd9393934k49f9fk002kd01
Author: John Doe <john.doe@example.com>
Date: Tue May 30 18:23:36 2020 -0500
imported the ldap3 module
commit fj83m3ld0d0d3m3ld0389303l3ld0d0d39dl
Author: John Doe <john.doe@example.com>
Date: Mon May 29 20:26:09 2020 -0500
updated logger to include stderr
Let's say there is a file named foo.txt in the currently selected branch of the cloned repository. In this example, every commit of foo.txt will be displayed.
AVOID TROUBLE
If the git log command does not return any output, this suggests that the file has not yet been added to the repository. Refer to Adding a file to Git using the git add command.
git log foo.txt
Sometimes, it's a tad easier to work with the --oneline flag.
~]# git log --oneline foo.txt
bk19sl1 updated LDAP queries to include Active Directory (AD)
8jfj20d imported the ldap3 module
afba75a updated logger to include stderr
Or even better, you can fine tune the output.
~]# git log --pretty=format:%h,%cn,%cd,%s --date=local foo.txt
bk19sl1,John Doe,Wed May 31 14:51:14 2020,updated LDAP queries to include Active Directory (AD)
8jfj20d,John Doe,Tue May 30 18:23:36 2020,imported the ldap3 module
afba75a,John Doe,Mon May 29 20:26:09 2020,updated logger to include stderr
Let's say you create a branch named feature/foo from the master branch, and you only want to list the commits in the feature/foo branch.
git log master..feature/foo
Did you find this article helpful?
If so, consider buying me a coffee over at