how to extract changeid using git log –format=?

I have gone through the documentation of

git log –format

  • Git-Flow undo a finished feature branch
  • resolve conflicts on git merge octopus
  • Understanding git submodule pulling and pushing
  • What's the best practice with git for multiple language implementations?
  • Git autodeploy on Windows 2003 with WAMP
  • Are there any high profile commercial users of GIT?
  • but I dont see a way to extract Change-Id (as in example below Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b) using the command git log –format.

    $ git log -1
      commit 29a6bb1a059aef021ac39d342499191278518d1d
      Author: A. U. Thor <>
      Date: Thu Aug 20 12:46:50 2009 -0700
          Improve foo widget by attaching a bar.
          We want a bar, because it improves the foo by providing more
          wizbangery to the dowhatimeanery.
          Bug: #42
          Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
          Signed-off-by: A. U. Thor <>
          CC: R. E. Viewer <>

    Is there a way to do this? Thanks in advance!

  • TeamCity Trigger on Pull Request vs Trigger on Merge
  • error on satellites after upgrade Gitlab from 5.4 to 6.0
  • How to tell `git diff <commit>` to diff untracked files that used to be tracked in `<commit>`?
  • There is any way to synchronize GIT and Subversion repositories?
  • Gitosis Directories of repositories per user?
  • fatal: 'origin' does not appear to be a git repository
  • 2 Solutions collect form web for “how to extract changeid using git log –format=?”

    As far as git is concerned, there is no change ID. (It’s just one line in the message body, and git can give you the message body, or suppress the message body, but it won’t give you individual lines out of the message body.1)

    To limit the output from git log to just the message body, use %b. To limit the output to just the message subject, use %s. To get the “raw body” (subject + body) use %B.

    In any case, you’ll then need some external program to snip out the interesting line(s) from the message body. As everyone else has already commented, grep is highly suited to this.

    1Unless you count the first line (the subject, %s, part) and mean the “raw body” (%B part) when you say “body”. Then %s will give you the first line. These descriptions, as usual, are somewhat vague and loose so that when someone says “the message body” it’s often worth clarifying what that means. “Did you mean the raw subject-and-body, or the body-minus-subject?” This is where using the actual format directive (%s, %b, %B) really shines, as those are unambiguous.

    You want to start with

    Then you add the “%b” for body flag to the format in the script to obtain the body of the commit message.

    Finally, you split the body entry into lines and you locate a line starting with Change-Id and parse it apart.

    GIT_COMMIT_FIELDS = ['id', 'author_name', 'author_email', 'date', 'message', 'body']
    GIT_LOG_FORMAT = ['%H', '%an', '%ae', '%ad', '%s', '%b']
    GIT_LOG_FORMAT = '%x1f'.join(GIT_LOG_FORMAT) + '%x1e'
    p = Popen('git log --format="%s"' % GIT_LOG_FORMAT, shell=True, stdout=PIPE)
    (log, _) = p.communicate()
    log = log.strip('\n\x1e').split("\x1e")
    log = [row.strip().split("\x1f") for row in log]
    log = [dict(zip(GIT_COMMIT_FIELDS, row)) for row in log]
    for row in log:
        for line in row['body'].split("\n"):
            if line.startswith('Change-Id:'):
                row['changeId'] = line.split(':')[1].strip()
    Git Baby is a git and github fan, let's start git clone.