git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Tracking changes in git with a change number....

From
Jeff King <peff@peff.net>
Date
Jul 12, 2011, 05:50 UTC
Message-ID
<20110712055008.GC11644@sigill.intra.peff.net>
In-Reply-To
<C785F567A08DDE449FD4590C91E6AD13CB34BE@naeamillez01v.nadsusea.nads.navy.mil>
On Mon, Jul 11, 2011 at 01:29:52PM -0400, Rice, James M CIV NSWCDD, K73 wrote:
Show 5 quoted lines
> Restating the problem.  I wish for our developers to be able to
> reference multiple commits with one number, and then find those
> commits via that number.  And I don't mind scripting to accomplish
> this.  I know, that CR # can be put in the commit message, then I can
> grep and parse the log, that is the hard way.

There are two ways to approach this: tell the CM tool about some git commits, or tell some git commits about the CR number.

For telling the CM tool about git commits, refer to them by their sha1 commit ids. If the commits are sequential, you can refer to the sequence by its endpoints. And then if you want to know which files were touched, you can just diff the endpoints, like:

  $ git diff-tree --name-only $start $end

It's not a number, exactly, but it is a fixed size (two 40-byte commit ids). Would that work in your CM tool?

If the commits aren't sequential, you can do something similar, but you have a variable-length list of commit ids, and you get the set of changed files like:

  $ for i in $commits; do
      git diff-tree --name-only $i |
      tail -n +2
    done | sort -u

If you want to do the reverse and tell git about CR numbers, then I don't think you have much option besides putting them in the commit message. Which means you'll need to grep to get them out. You can do something like:

  $ git log --grep='CR#' --pretty=format: --name-only
-Peff
Previous: Damien WyartNext: Stephen Bash
Message 3 of 5 in “Tracking changes in git with a change number....”
  1. Rice, James M CIV NSWCDD, K73Jul 11, 2011
  2. Damien WyartJul 12, 2011
  3. Jeff KingJul 12, 2011
  4. Stephen BashJul 12, 2011
  5. Rice, James M CIV NSWCDD, K73Jul 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.