Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formal notation for Git (repository, branch, commit) tuple

Use case: I am logging my CI pipeline that deploys the tip of a specific branch of a repository.

Although plain, verbose English is always an option, a standardized format for representing a specific commit from a specific branch of a repository seems more appropriate.

I would imagine that such a notation would be indispensable for logging/documentation purposes; something along the lines of:

TIMESTAMP: REPO<separator1>BRANCH<separator2>COMMIT -> HOST

If this can be generalized across version control systems, all the better. My Google searches have not thrown up anything worthwhile on the subject.

like image 524
Slaiyer Avatar asked Aug 12 '26 22:08

Slaiyer


2 Answers

There is no such settings and configurations for git itself to show repo, branch, commit together.

As Jonathon mentioned, the relationship among repo, branch and commit usually does not as 1:1:1.

And if you want to get if a certain commit belongs to a remote repo or a branch, or which repo, branch(es) the certain commit belongs to, you can use use scripts to achieve it. Main commands used for the script as:

  • Check a certain commit belongs to which branch(es):

    git branch --contains <commit>
    
  • Check if a branch has tracking branch (in order to get the remote repo):

    git rev-parse --abbrev-ref <branch>@{upstream}
    
like image 93
Marina Liu Avatar answered Aug 14 '26 12:08

Marina Liu


Proposition

timestamp: repo/branch#commit -> HOST

e.g.

20200506_134321: my-site/master#c37107b0c -> HOST
like image 30
Kamil Kiełczewski Avatar answered Aug 14 '26 12:08

Kamil Kiełczewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!