Skip to content

Instantly share code, notes, and snippets.

@rhaberkorn
Created January 31, 2019 17:52
Show Gist options
  • Save rhaberkorn/09fd768428a8dbe849e08312598d5bc3 to your computer and use it in GitHub Desktop.
Save rhaberkorn/09fd768428a8dbe849e08312598d5bc3 to your computer and use it in GitHub Desktop.
Rewrite Git tag to new commit, preserving annotations
#!/bin/bash
# git-move-tag <tag-name> <target>
tagName=$1
# Support passing branch/tag names (not just full commit hashes)
newTarget=$(git rev-parse $2^{commit})
git cat-file -p refs/tags/$tagName |
sed "1 s/^object .*$/object $newTarget/g" |
git hash-object -w --stdin -t tag |
xargs -I {} git update-ref refs/tags/$tagName {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment