I am trying to show commits (excluding merge commits) which were added to the master
branch in the last 24 hours. Currently i am using this command for that:
git log --format=format:%s --no-merges --since='24 hours ago'
However this has a problem: if a commit is older than 24 hours, but merged into the master
branch in the last 24 hours, the command will not list the commit. Is it possible to show commits added to the master
branch in last 24 hours, and not commits created in last 24 hours?
Please note i execute this in a clean CI workspace, so git reflog
cannot help me.
Thanks in advance!
On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.
For example, if you want to see only 1 commit in your git log or you want to see 2 commits or it can be any number depending on the total number of commits you have done in your git repository. The command for that would be git log -n where n represents the number up to which commit you to want to see the logs.
To see the merge commit's message and other details, use git show-merge with the same arguments.
By Amount. The most basic filtering option for git log is to limit the number of commits that are displayed. When you're only interested in the last few commits, this saves you the trouble of viewing all the commits in a page. You can limit git log 's output by including the - option.
I think rev-list
is what you want.
Try this:
git rev-list --no-merges '^<24-hour-old-commit>' HEAD
That should list all the non-merge commits that are reachable from commit HEAD
, but not reachable from from commit <24-hour-old-commit>
.
For example, in this revision graph, it'll list the upper case commits, but not lower case:
a - b - c - 24h - H - i - J - K - HEAD
\ /
D - E - F - G '
Commits H
, J
, K
, and HEAD
are all younger than 24 hours old. Commit i
is also younger, but is omitted as it is a merge commit. Commits D
, E
, F
, and G
may be any age, but have only been merged within the last 24 hours, so they are listed also.
Within the above command, --max-age
or --since
options will have the same problem as you have with git log
, but they can be used to find <24-hour-old-commit>
for you:
git rev-list -n1 --before="24 hours" --first-parent HEAD
That is, "give only 1 commit ID, that must be at least 24 hours old, and is on the current branch".
Putting it all together:
git rev-list --no-merges HEAD \
--not $(git rev-list -n1 --before="24 hours" --first-parent HEAD)
(Note: --not abcdef
is another way to say ^abcdef
except that it applies to all following arguments, hence reordering the options.)
The default output of rev-list
is just raw revisions, but you can make it more like git log
using the --pretty
option. --pretty=short
is approximately the same as you're used to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With