Build ID from Git (updated)

A simple build_id can be generated from Git via:

git log --pretty=oneline | wc -l

which will give you something like 9682

And while this will likely vary by branch, you really want to base a build id only from the branch you are deploying to production (in our case, release) anyway. It won’t let you name a work-in-progress, so that might be an issue for some people but also might enforce good practice by not letting you name a release until it’s “done”. As long as the naming is consistent, it should work. Of course in this scenario if you hot/bug-fix release that actual value will go up, but that’s not really what we care about, seems like our criterion would be:

  • something we can generate in an automated build
  • something sequential so it’s easy to tell the order to other builds
  • something unique (potential edge cases it may not be, but would be very edge-case)

    If you want a sequential number to give ordinal context but hash info for relevancy can use:

    echo $(git log --pretty=oneline | wc -l)-$(git log -1 '--pretty=format:%h')

    which will give you something like 9682-36a51c8

    log count + “-” + truncated last commit hash. You could add zero-padding or similar if desired.

    This seems particularly useful if you aren’t tagging at the time you create the id. Otherwise, you would be able to get the hash from the tag.

  • Get build ID from Git repo

    git log --pretty=oneline | wc -l

    GitHub-Pivotal Tracker commit format

    Easy integration to change status on Pivotal Tracker when using GitHub. After sync’ing the services via API key, you can use the format:

    [Delivers #12345679]

    verbs include:
    started, fixed, completed, finished, delivered.

    see: https://www.pivotaltracker.com/help/api?version=v5

    The minimum commit message string that will allow Tracker to associate a /source_commits POST with a story and create a comment is a single story ID enclosed in square brackets: ‘[#12345678]‘. A more typical message, indicating that one commit completes two stories (which need not be in the same Tracker project), might look like this: ‘finally [finished #12345678 #12345779], fixes client/server integration glitch’

    If an included story was not already started (it was in the “not started” state), an update to that story from /source_commits that doesn’t contain any other state-change information will automatically start the story.

    To automatically finish a story by using a commit message, include “fixed”, “completed”, or “finished” in the square brackets in addition to the story ID. You may use different cases or forms of these verbs, such as “Fix” or “FIXES”, and they may appear before or after the story ID.

    Git: show files just merged

    git log -m --name-only

    Git Tip: How to “Merge” Specific Files from Another Branch

    Git Tip: How to “Merge” Specific Files from Another Branch

    basically:
    git checkout source_branch <paths>...

    then commit.

    also look into adding –patch or –merge to checkout:
    http://git-scm.com/docs/git-checkout