git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Plumbing to rename a ref?

From
SOSergei Organov <osv@javad.com>
Date
May 23, 2014, 10:11 UTC
Message-ID
<87ha4golck.fsf@osv.gnss.ru>
Hello,

After convertion of a project from CVS to git, I'd like to rename some references in the created git repository (before it's published, so no problems here). Is there a plumbing that would do:

git rename-ref <old_name> <new_name>
for me?
For reference, the (ugly) solution I currrently use is:

# Renamve branches/tags for brevity. # # e.g.: version-3-5-branch -> v3.5-branch #

sed_cmd='sed "s/version-/v/g" | sed "s/\([0-9]\)-\([0-9]\)/\1.\2/g" | sed "s/\([0-9]\)-\([0-9]\)/\1.\2/g"'
if [ -f "packed-refs" ]; then
    rm -rf "packed-refs.new"
    cat "packed-refs" | eval "$sed_cmd" > "packed-refs.new" && mv "packed-refs.new" "packed-refs"
fi
git for-each-ref --format="%(refname)" |
while read -r; do
    ref="$REPLY"
    if [ -f "$ref" ]; then
        new_ref=`echo "$ref" | eval "$sed_cmd"`
        if [ "$ref" != "$new_ref" ]; then
            echo "$ref -> $new_ref"
            mv "$ref" "$new_ref"
        fi
    fi
done
-- Sergey.
Next: John Keeping
Message 1 of 8 in “Plumbing to rename a ref?”
  1. Sergei OrganovMay 23, 2014
  2. John KeepingMay 23, 2014
  3. Sergei OrganovMay 23, 2014
  4. Jeff KingMay 23, 2014
  5. Junio C HamanoMay 23, 2014
  6. Jeff KingMay 23, 2014
  7. Junio C HamanoMay 23, 2014
  8. John KeepingMay 23, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.