# Script to backdate tags

7 messages from 2007-09-30 to 2007-10-15. Participants: Michael Olson, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/10084

## Michael Olson, 2007-09-30 03:16

Subject: Script to backdate tags
Message-ID: <87bqbklu5r.fsf@hariken.mwolson.org>
URL: https://gitlist.dev/e/87bqbklu5r.fsf%40hariken.mwolson.org

```
After importing one of my projects from Arch, I wanted to add tags that
indicated its major releases.  Unfortunately, these tags for older
releases would show up before the more recent releases in the gitweb
output.  I searched in vain for a way of backdating tags, and finally
decided to make a script to do this for me.  Here it is.

This may run into issues if someone uses the "\" character in their tag
names, but I didn't want to bother fixing this until it was affirmed
that this script would be considered generally useful.



#!/bin/sh
#
# git-backdate-tag: Change the date of an existing tag, replacing the
# tag reference with the newly-generated tag object.
#
# Usage: git-backdate-tag TAG DATE

usage () {
    echo "Usage: git-backdate-tag TAG DATE"
}

if [ -n "$3" ]; then
    usage
    exit 1
elif [ -z "$2" ]; then
    usage
    exit 1
fi

# Set parameters
tag="$1"
date=$(date --date="$2" +%s)

if [ $? -ne 0 ]; then
    echo Could not parse date
    exit 1
fi

# Replace old date with new date
newtagobj=$(git cat-file tag "$tag" | \
    sed -r -e "s/^(tagger .+) ([^ \\n]+) ([^ \\n]+)\$/\1 $date \3/1" | \
    git mktag)

if [ $? -ne 0 ]; then
    echo Could not create replacement tag object
    exit 1
fi

# Set tag to new tag object
git update-ref refs/tags/"$tag" $newtagobj



-- 
       Michael Olson -- FSF Associate Member #652     |
 http://mwolson.org/ -- Jabber: mwolson_at_hcoop.net  |  /` |\ | | |
            Sysadmin -- Hobbies: Lisp, GP2X, HCoop    | |_] | \| |_|
Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

```

## Michael Olson, 2007-09-30 04:29

Subject: Re: Script to backdate tags
Message-ID: <871wcglqrg.fsf@hariken.mwolson.org>
URL: https://gitlist.dev/e/871wcglqrg.fsf%40hariken.mwolson.org
In-Reply-To: <87bqbklu5r.fsf@hariken.mwolson.org>

```
Michael Olson <mwolson@gnu.org> writes:

> This may run into issues if someone uses the "\" character in their
> tag names, [snip].

In fact, this isn't the case after all.

-- 
       Michael Olson -- FSF Associate Member #652     |
 http://mwolson.org/ -- Jabber: mwolson_at_hcoop.net  |  /` |\ | | |
            Sysadmin -- Hobbies: Lisp, GP2X, HCoop    | |_] | \| |_|
Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

```

## Junio C Hamano, 2007-09-30 05:16

Subject: Re: Script to backdate tags
Message-ID: <7vps00ivgh.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vps00ivgh.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <871wcglqrg.fsf@hariken.mwolson.org>

```
Michael Olson <mwolson@gnu.org> writes:

> Michael Olson <mwolson@gnu.org> writes:
>
>> This may run into issues if someone uses the "\" character in their
>> tag names, [snip].
>
> In fact, this isn't the case after all.

Wouldn't it be easier to create the tag with the desired
timestamp from the beginning, by exporting GIT_COMMITTER_DATE?

```

## Michael Olson, 2007-09-30 06:27

Subject: Re: Script to backdate tags
Message-ID: <87hclck6qy.fsf@hariken.mwolson.org>
URL: https://gitlist.dev/e/87hclck6qy.fsf%40hariken.mwolson.org
In-Reply-To: <7vps00ivgh.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Michael Olson <mwolson@gnu.org> writes:
>
>> After importing one of my projects from Arch, I wanted to add tags
>> that indicated its major releases.  Unfortunately, these tags for
>> older releases would show up before the more recent releases in the
>> gitweb output.  I searched in vain for a way of backdating tags, and
>> finally decided to make a script to do this for me.  Here it is.
>
> Wouldn't it be easier to create the tag with the desired
> timestamp from the beginning, by exporting GIT_COMMITTER_DATE?

Ah, I didn't know about that environment variable.

Would it be possible to mention that option on the git-tag manpage?
Backdating tags is very handy for projects which are converting their
entire history from another VCS to git, and wish to denote releases that
were not previously tagged.  (Making a separate Arch branch for every
single release was such a hassle that I didn't bother with it.  Git is
much nicer in that area with its concept of tags and tag objects.)

-- 
       Michael Olson -- FSF Associate Member #652     |
 http://mwolson.org/ -- Jabber: mwolson_at_hcoop.net  |  /` |\ | | |
            Sysadmin -- Hobbies: Lisp, GP2X, HCoop    | |_] | \| |_|
Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

```

## Michael Olson, 2007-10-15 17:51

Subject: [PATCH] Documentation/git-tag.txt: Document how to backdate tags
Message-ID: <87lka4cllp.fsf@hariken.mwolson.org>
URL: https://gitlist.dev/e/87lka4cllp.fsf%40hariken.mwolson.org
In-Reply-To: <7vd4w0iqd5.fsf@gitster.siamese.dyndns.org>

```
Added a new section beneath "On Automatic following" called "On
Backdating Tags".  This includes an explanation of when to use this
method, a brief explanation of the kind of date that can be used in
GIT_AUTHOR_DATE, and an example invocation of git-tag using a custom
setting of GIT_AUTHOR_DATE.

Signed-off-by: Michael W. Olson <mwolson@gnu.org>
---

[Resending, this time without trying to send through Gmane and munge
Reply-To.]

Junio C Hamano <gitster@pobox.com> writes:

> Michael Olson <mwolson@gnu.org> writes:
>
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> Wouldn't it be easier to create the tag with the desired
>>> timestamp from the beginning, by exporting GIT_COMMITTER_DATE?
>>
>> Ah, I didn't know about that environment variable.
>>
>> Would it be possible to mention that option on the git-tag manpage?
>
> Surely, I am kind of surprised if it weren't, but apparently you
> did not find it.  Please make it so.

 Documentation/git-tag.txt |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 990ae4f..2966aa2 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -214,6 +214,27 @@ having tracking branches.  Again, the heuristic to automatically
 follow such tags is a good thing.
 
 
+On Backdating Tags
+~~~~~~~~~~~~~~~~~~
+
+If you have imported some changes from another VCS and would like
+to add tags for major releases of you work, it is useful to be able
+to specify the date to embed inside of the tag object.  The data in
+the tag object affects, for example, the ordering of tags in the
+gitweb interface.
+
+To set the date used in future tag objects, set the environment
+variable GIT_AUTHOR_DATE to one or more of the date and time.  The
+date and time can be specified in a number of ways; the most common
+is "YYYY-MM-DD HH:MM".
+
+An example follows.
+
+------------
+$ GIT_AUTHOR_DATE="2006-10-02 10:31" git tag -s v1.0.1
+------------
+
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>,
-- 
1.5.3.4

```

## Jeff King, 2007-10-15 20:35

Subject: Re: [PATCH] Documentation/git-tag.txt: Document how to backdate tags
Message-ID: <20071015203523.GA4428@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20071015203523.GA4428%40sigill.intra.peff.net
In-Reply-To: <87lka4cllp.fsf@hariken.mwolson.org>

```
On Mon, Oct 15, 2007 at 01:51:30PM -0400, Michael Olson wrote:

> +On Backdating Tags
> +~~~~~~~~~~~~~~~~~~
> +
> +If you have imported some changes from another VCS and would like
> +to add tags for major releases of you work, it is useful to be able

s/you/your/

-Peff

```

## Michael Olson, 2007-10-15 22:53

Subject: Re: [PATCH] Documentation/git-tag.txt: Document how to backdate tags
Message-ID: <876418htvs.fsf@hariken.mwolson.org>
URL: https://gitlist.dev/e/876418htvs.fsf%40hariken.mwolson.org
In-Reply-To: <20071015203523.GA4428@sigill.intra.peff.net>

```
Added a new section beneath "On Automatic following" called "On
Backdating Tags".  This includes an explanation of when to use this
method, a brief explanation of the kind of date that can be used in
GIT_AUTHOR_DATE, and an example invocation of git-tag using a custom
setting of GIT_AUTHOR_DATE.

Signed-off-by: Michael W. Olson <mwolson@gnu.org>
---

Jeff King <peff@peff.net> writes:

> On Mon, Oct 15, 2007 at 01:51:30PM -0400, Michael Olson wrote:
>
>> +On Backdating Tags
>> +~~~~~~~~~~~~~~~~~~
>> +
>> +If you have imported some changes from another VCS and would like
>> +to add tags for major releases of you work, it is useful to be able
>
> s/you/your/

Fixed; thanks.

 Documentation/git-tag.txt |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 990ae4f..5cc9da4 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -214,6 +214,27 @@ having tracking branches.  Again, the heuristic to automatically
 follow such tags is a good thing.
 
 
+On Backdating Tags
+~~~~~~~~~~~~~~~~~~
+
+If you have imported some changes from another VCS and would like
+to add tags for major releases of your work, it is useful to be
+able to specify the date to embed inside of the tag object.  The
+data in the tag object affects, for example, the ordering of tags
+in the gitweb interface.
+
+To set the date used in future tag objects, set the environment
+variable GIT_AUTHOR_DATE to one or more of the date and time.  The
+date and time can be specified in a number of ways; the most common
+is "YYYY-MM-DD HH:MM".
+
+An example follows.
+
+------------
+$ GIT_AUTHOR_DATE="2006-10-02 10:31" git tag -s v1.0.1
+------------
+
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>,
-- 
1.5.3.4

```
