Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to find when a commit was merged into master?

Tags:

git

git-log

I want to create a metric in my project that measures how long does a commit take from its creation till to get into the master branch.

Is it possible? It looks like for fast-forwarded commits I can't get this info from the git log.

If I can get a snapshot of the repository X days ago, maybe I can calculate it. Another option is to get a log that registers when a branch HEAD was modified.

Update: If you create an annotated tag at each release, you can just see the date of the tag that included the commit. Here is how to list the commits included in a tag

like image 390
neves Avatar asked Nov 21 '18 18:11

neves


People also ask

Does git merge keep history?

In the Conceptual Overview section, we saw how a feature branch can incorporate upstream changes from main using either git merge or git rebase . Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

Which command is used to display merge history in git?

The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order — that is, the most recent commits show up first.

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 see when a change was last committed?

To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.


1 Answers

It is not easy, considering the commit itself does not know in which branch it is.
It does not keep track of branch "events" which would mention it was created in branch X, and then merge (possibly fast-forward) in branch Y.

Only git reflog registers HEAD changes, but it is limited in time.

As mentioned by the OP, you need to add a metadata (like an annotated tag, but you could also consider a git notes) in order to memorize the information you need.

like image 93
VonC Avatar answered Oct 23 '22 08:10

VonC