⊗gtPmBsLHF 28 of 65 menu

Flags to Limit Git Commit History Output

You can also limit the output of commit history based on the time when they were made. For example, the flag --since=1day will display commits made 1 days ago. The full list of flags for limiting the output of commits is below:

Flag Description
-(n) Shows the latest commits, given the specified number.
--since, --after* Displays commits made after the specified date.
--until, --before* Displays commits made before the specified date.
--author* Displays commits for files with the specified author.
--committer* Displays commits made by the specified committer, i.e. the user making the changes. The file author and the committer may be different users.
grep Searches for and displays commits whose message or note contains the specified string.

Some restrictive flags have mandatory requirements to add the sign = after their name and the parameter by which we restrict the output of the commit history. These flags are marked in the table *.

Example . Displaying the latest commits

Let's print the last two commits to the console:

git log -2

After executing the command we will see:

commit 33498ca885348fba6060ad4c459963d9e756c8b6 (HEAD -> master) Author: root <root@node.com> Date: Tue Sep 12 10:52:30 2023 +0100 Story1 commit bb6945ff7c73c88981a0b2523c32e30f472fd918 Author: root <root@node.com> Date: Tue Sep 12 10:47:27 2023 +0100 text

Example . List commits made after a given date

Let's print to the console the commits made after 11 September 2023:

git log --since="2023-09-11"

After executing the command we will see:

commit 33498ca885348fba6060ad4c459963d9e756c8b6 (HEAD -> master) Author: root <root@node.com> Date: Tue Sep 12 10:52:30 2023 +0100 Story1 commit bb6945ff7c73c88981a0b2523c32e30f472fd918 Author: root <root@node.com> Date: Tue Sep 12 10:47:27 2023 +0100 text

Example . List commits made before a specified date

Now let's print to the console the commits made before 11 September 2023:

git log --until="2023-09-11"

After executing the command we will see:

commit a99c51a34d6a89be9c56127e18a1e574d6188d61 Author: root <root@node.com> Date: Fri Jun 16 15:20:43 2023 +0100 initial commit

Example . List commits made by the specified author of the files

Let's print to the console all commits for files created by user 'user':

git log --author="user"

After executing the command we will see:

commit 9c51a34d188d61a6a89be9c56127e18a1e574d69 Author: user <user@node.com> Date: Fri Jun 10 10:10:23 2022 +0100 initial commit

Example . Print commits made by the specified committer

Now let's print to the console all commits made by user 'root':

git log --committer="root"

After executing the command we will see:

commit 33498ca885348fba6060ad4c459963d9e756c8b6 (HEAD -> master) Author: root <root@node.com> Date: Tue Sep 12 10:52:30 2023 +0100 Story1 commit bb6945ff7c73c88981a0b2523c32e30f472fd918 Author: root <root@node.com> Date: Tue Sep 12 10:47:27 2023 +0100 text commit a99c51a34d6a89be9c56127e18a1e574d6188d61 Author: root <root@node.com> Date: Fri Jun 16 15:20:43 2023 +0100 initial commit

Example . Commit output, specified note

Let's print to the console all commits that contain the string 'text':

git log --grep "text"

After executing the command we will see:

commit bb6945ff7c73c88981a0b2523c32e30f472fd918 Author: root <root@node.com> Date: Tue Sep 12 10:47:27 2023 +0100 text
enru