Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log commits added to master in last 24 hours

Tags:

git

git-log

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!

like image 268
WonderCsabo Avatar asked Oct 16 '15 07:10

WonderCsabo


People also ask

How do I see my commit history?

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.

How do I see more commits in git log?

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.

How can you tell when a commit was merged?

To see the merge commit's message and other details, use git show-merge with the same arguments.

How do I limit a git log?

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.


1 Answers

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.

like image 188
ams Avatar answered Oct 21 '22 06:10

ams