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.
Let's say there is a file named foo.txt in the currently selected branch of the cloned repository. The git log command can be used to view the history of commits. 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
The log will display entries like this.
commit mks910122020slsmm3lsosos020399489sl
Author: John Doe <john.doe@example.com>
Date: Wed May 31 14:51:14 2020 -0500
Third commitment
commit dkci85474fjfdkd9393934k49f9fk002kd01
Author: John Doe <john.doe@example.com>
Date: Tue May 30 18:23:36 2020 -0500
Second commitment
commit fj83m3ld0d0d3m3ld0389303l3ld0d0d39dl
Author: John Doe <john.doe@example.com>
Date: Mon May 29 20:26:09 2020 -0500
First commitment
Sometimes, it's a tad easier to work witht the --oneline flag.
~]# git log --oneline foo.txt
bk19sl1 Third commit
8jfj20d Second commit
afba75a First commit
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,Third commit
8jfj20d,John Doe,Tue May 30 18:23:36 2020,Second commit
afba75a,John Doe,Mon May 29 20:26:09 2020,First commit
Did you find this article helpful?
If so, consider buying me a coffee over at