51

How you I change the connected commit on a github release? Release

I want to change it to an earlier commit, because I created the release afterwards (after some commits to release 0.9)

1 Answer 1

67

When you consider the GitHub API for creating a release, you see a release needs:

  • a tag
  • a commit referenced by that tag

So you need to move your tag (locally first, then push it to your GitHub repo)

git tag -f -a <tagname> [<commit> | <object>]
# or, to avoid an editor
git tag -m "tag message" -f -a <tagname> [<commit> | <object>]

git push -f <remotename> refs/tags/<tagname>

for Example:

git tag -m "moving tag to new commit" -f -a my_tag [commit hash]
git push -f origin refs/tags/my_tag

Then see if that is enough for the release to be updated.
(See "How do you push a tag to a remote repository using Git?")

If not, you might have to delete that release, and recreate it on the same tag (which will refer to the new commit)


After doing this, if you get an error would clobber existing tag, then you need to sync local tags with remote using git fetch --tags -f and the push new commits.

Sign up to request clarification or add additional context in comments.

8 Comments

I did the first line before posting here, but it did not work. The second line fixed it :)
how do you specify the commit id in the first command? My commit id is: 10a4ff2. So what should my command be? git tag -f -a v1.2.0 ...???...
@ParthTamane Simply git tag -f -a v1.2.0 10a4ff2, as illustrated in git-scm.com/book/en/v2/Git-Basics-Tagging#_tagging_later
@Sam Sure, I have edited the answer accordingly. You can also edit it directly: I will review and approve your edit.
@Gangula Running with -m (git tag -m "tag message" -f -a <tagname> [<commit> | <object>]) should be enough to avoid the editor part.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.