git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Kirill Likhodedov <kirill.likhodedov@jetbrains.com>
Cc: git <git@vger.kernel.org>
Subject: Re: How to add custom metadata to Git commit object
Date: Mon, 30 May 2016 14:30:16 -0400	[thread overview]
Message-ID: <20160530183016.GB17253@sigill.intra.peff.net> (raw)
In-Reply-To: <959E96F7-0FF3-4336-B098-58836136DB08@jetbrains.com>

On Mon, May 30, 2016 at 08:58:08PM +0300, Kirill Likhodedov wrote:

> Is it possible to add custom metadata to Git commit object?  Such
> metadata should be ignored by Git commands, but could be used by a
> 3-party tool which knows the format and knows where to look.

Yes. The recommended place to stick this is in a "trailer" at the bottom
of the commit message, like:

  Rename-detection-hint: foo.java -> bar.java

or whatever scheme is useful to your tool.

> I assume that this should be possible, given that Git objects are
> actually patches, and patches can contain additional details. But can
> this be done with the help of Git commands?

Git objects aren't actually patches. Try:

  git cat-file commit HEAD

to see what an actual commit object looks like. You will see that there
are user-invisible headers before the commit message, too, but we do not
usually recommend people to add new headers here, as their semantics
would be unclear to git. For example, when rebasing such a commit,
should the header be preserved or not? It depends on its meaning.
Whereas commit messages are always preserved.

> There are git-notes, which could be used for the purpose, but they are
> visible to the user via standard Git command, and could be used by the
> user for other purposes, so they are not very suitable for the task.

Notes would work for this, too, but their main advantage is that they
can be created _after_ a commit has already been made (whereas anything
in the commit object itself will influence its sha1 id).

-Peff

  parent reply	other threads:[~2016-05-30 18:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 17:58 How to add custom metadata to Git commit object Kirill Likhodedov
2016-05-30 18:24 ` Konstantin Khomoutov
2016-05-30 18:30 ` Jeff King [this message]
2016-05-30 18:52   ` Junio C Hamano
2016-05-31 15:17     ` Kirill Likhodedov
2016-05-31 15:25       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160530183016.GB17253@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=kirill.likhodedov@jetbrains.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).