Skip to content

Instantly share code, notes, and snippets.

@frederikheld
Created October 4, 2023 12:45
Show Gist options
  • Save frederikheld/191844766e82f669da26dac26e23ef8e to your computer and use it in GitHub Desktop.
Save frederikheld/191844766e82f669da26dac26e23ef8e to your computer and use it in GitHub Desktop.
Create releases from old commits

If you create a new release in GitHub, you will either create a new tag (which will point to the most recent commit on main) or choose an existing tag (that might point to an older commit).

If you want to create releases from old commits (e.g. because you forgot to create a realease or didn't work with releases back then), there is a problem with this: when creating a tag for a specific commit in the past, GitHub only lets you pick from the most recent commits, so the commit you want to tag will not show up in the list.

Luckily, you can tag older commits locally [1]:

  1. Find the commit on GitHub. If it is from a Pull Request, you can look into the closed Pull Requests. Within the PR you'll find a link to the commit.
  2. Copy the commit hash from your browser's address bar.
  3. Check out the commit in your local repo: $ git checkout <commit hash>
  4. Now add the tag. There are two ways to add the tag:
    1. either you add the tag with the current date, which will date the release to the day when you actually created it. Releses might be listed out of order: git tag -a <tag name> -m"<tag name>"
    2. or you add the tag with the date of the commit, which will date the release to that day in the past. Releases will be listed in order: GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a <tag name> -m"<tag name>" [2]
  5. Push the new tag to GitHub: $ git push origin <tag name>
  6. Now you can select this tag when creating a new release

Further readings:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment