threads / discuss / 29722

[BugReport] git tag -a / git show

Subject: [BugReport] git tag -a / git show

## tl;dr

9 messages between Feb 24, 2012 and Feb 24, 2012.

replies: 8people: 5as markdown or json

Romain Vimont (®om)· Feb 24, 2012, 10:24 UTC · lore

$ git --version git version 1.7.5.4

$ git log --pretty=online 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff This is the last commit a4702c69c28484d357179166cf3b116764da20a4 This is a commit

Now, I edit some files (for example in a config file "mock_data=true"), then I want to tag without commiting this change.

$ git tag -a v0.1 -m 'My v0.1 with mock data'
$ git show v0.1
tag v0.1
Tagger: Me <me@me.me>
Date:   Fri Feb 24 11:23:38 2012 +0100
     My v0.1 with mock data
commit 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff
Author: Me <me@me.me>
Date:   Fri Feb 24 11:14:19 2012 +0100
     This is the last commit
diff --git a/myfile b/myfile
index 8430bf6..20feeb6 100644
...


And it shows the diff between a4702c69c28484d357179166cf3b116764da20a4 
and 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff (the two last commits).
Instead, it should show the diff between 
0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff (the last commit) and v0.1 (the 
tag).

Best regards,
®om
Zbigniew Jędrzejewski-Szmek· Feb 24, 2012, 19:27 UTC · re: Romain Vimont (®om) · lore

Re: [BugReport] git tag -a / git show

On 02/24/2012 11:24 AM, Romain Vimont (®om) wrote:
Show 8 quoted lines
> $ git log --pretty=online
> 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff This is the last commit
> a4702c69c28484d357179166cf3b116764da20a4 This is a commit
>
> Now, I edit some files (for example in a config file "mock_data=true"),
> then I want to tag without commiting this change.
>
> $ git tag -a v0.1 -m 'My v0.1 with mock data'
> And it shows the diff between a4702c69c28484d357179166cf3b116764da20a4
> and 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff (the two last commits).

Hi Romain, git tag attaches the tag to the last commit, 0ef41513 in your case. Dirty changes in your tree are ignored by the tag command. You would have to commit them first, and attach the tag to this new commit.

zbyszek
Romain Vimont (®om)· Feb 24, 2012, 19:55 UTC · re: Zbigniew Jędrzejewski-Szmek · lore

Re: [BugReport] git tag -a / git show

Thank you for your answer.

After my message this morning, that's what I did: I commited with the mock data then tag.

Tonight, I just tried something which do exactly what I wanted to do this morning:

$ git checkout -b temp $ git commit -a -m 'My config file with mock_data=true' $ git tag -a v0.1 -m v0.1 $ git checkout master $ git branch -D temp

With these commands, the tag is associated to a commit which is not in any branch.

Regards, ©om

Le vendredi 24 février 2012 à 20:27 +0100, Zbigniew Jędrzejewski-Szmek a écrit :

Show 20 quoted lines
> On 02/24/2012 11:24 AM, Romain Vimont (®om) wrote:
> > $ git log --pretty=online
> > 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff This is the last commit
> > a4702c69c28484d357179166cf3b116764da20a4 This is a commit
> >
> > Now, I edit some files (for example in a config file "mock_data=true"),
> > then I want to tag without commiting this change.
> >
> > $ git tag -a v0.1 -m 'My v0.1 with mock data'
> 
> > And it shows the diff between a4702c69c28484d357179166cf3b116764da20a4
> > and 0ef41513d0b6d0ad28f21d0ac1da7096ad1dc6ff (the two last commits).
> 
> Hi Romain,
> git tag attaches the tag to the last commit, 0ef41513 in your case. 
> Dirty changes in your tree are ignored by the tag command. You would 
> have to commit them first, and attach the tag to this new commit.
> 
> zbyszek
> 
Jeff King· Feb 24, 2012, 20:52 UTC · re: Romain Vimont (®om) · lore

Re: [BugReport] git tag -a / git show

On Fri, Feb 24, 2012 at 08:55:45PM +0100, Romain Vimont (®om) wrote:
Show 8 quoted lines
> Tonight, I just tried something which do exactly what I wanted to do
> this morning:
> 
> $ git checkout -b temp
> $ git commit -a -m 'My config file with mock_data=true'
> $ git tag -a v0.1 -m v0.1
> $ git checkout master
> $ git branch -D temp

There is nothing at all wrong with the commands above, but you might be interested to know that you can do it without the temporary branch:

  $ git commit -a -m 'My config...'
  $ git tag -m v0.1 v0.1
  $ git reset HEAD^

The final reset will rewind your branch tip and the index state to what it was before the commit, but will leave the files in the working tree untouched.

-Peff
Romain Vimont (®om)· Feb 24, 2012, 21:42 UTC · re: Jeff King · lore

Re: [BugReport] git tag -a / git show

Thank you, I didn't know this '^' thing ;-)
Le vendredi 24 février 2012 à 15:52 -0500, Jeff King a écrit :
Show 24 quoted lines
> On Fri, Feb 24, 2012 at 08:55:45PM +0100, Romain Vimont (®om) wrote:
> 
> > Tonight, I just tried something which do exactly what I wanted to do
> > this morning:
> > 
> > $ git checkout -b temp
> > $ git commit -a -m 'My config file with mock_data=true'
> > $ git tag -a v0.1 -m v0.1
> > $ git checkout master
> > $ git branch -D temp
> 
> There is nothing at all wrong with the commands above, but you might be
> interested to know that you can do it without the temporary branch:
> 
>   $ git commit -a -m 'My config...'
>   $ git tag -m v0.1 v0.1
>   $ git reset HEAD^
> 
> The final reset will rewind your branch tip and the index state to what
> it was before the commit, but will leave the files in the working tree
> untouched.
> 
> -Peff
> 
Jeff King· Feb 24, 2012, 21:44 UTC · re: Romain Vimont (®om) · lore

Re: [BugReport] git tag -a / git show

On Fri, Feb 24, 2012 at 10:42:43PM +0100, Romain Vimont (®om) wrote:
> Thank you, I didn't know this '^' thing ;-)

You might find the "Specifying Revisions" section of "git help rev-parse" enlightening. :)

-Peff
Junio C Hamano· Feb 24, 2012, 19:50 UTC · re: Romain Vimont (®om) · lore

Re: [Not A BugReport] git tag -a / git show

"Romain Vimont (®om)" <rom@rom1v.com> writes:
> Now, I edit some files (for example in a config file
> "mock_data=true"), then I want to tag without commiting this change.

Tag applies to an existing commit [*1*]. Your change in the working tree is purely ephemeral until it is committed.

In other words, you don't "tag without committing".
> $ git tag -a v0.1 -m 'My v0.1 with mock data'

By omitting the [<head>] part from your command line for a command whose usage is:

  usage: git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]

you asked <head> to default to HEAD, the most recent commit, so the tag points at your 0ef41513d0b6 (This is the last commit). The tag message should say "My v0.1" without anything else.

And show naturally shows the patch to bring its parent to that tagged commit.

If you wanted to keep your mainline pristine without mock data, and want to have a playpen that uses mock data, a way to do so is to use a separate branch, e.g.

        $ git checkout -b playpen

Now, you are on your 'playpen' branch that was forked from the tip of whatever branch you were on, perhaps 'master'. Then commit that state with whatever change that is specific to the playpen you want to keep out of the mainline:

	$ edit config.txt ;# set mock_data=true
        $ git commit -a -m 'With mock data'

You can optionally tag the resulting commit if you want to. You are still on the 'playpen' branch, so you probably would want to come back to the previous branch after you are done.

[Footnote]

*1* technically, tag can apply to any type of object, but it is most common to apply to a commit.

Romain Vimont (®om)· Feb 24, 2012, 19:58 UTC · re: Junio C Hamano · lore

Re: [Not A BugReport] git tag -a / git show

Thank you for the details.
> *1* technically, tag can apply to any type of object, but it is most
common to apply to a commit.
To what other type of object can you apply a tag ?
Good evening.
Le vendredi 24 février 2012 à 11:50 -0800, Junio C Hamano a écrit :
Show 48 quoted lines
> "Romain Vimont (®om)" <rom@rom1v.com> writes:
> 
> > Now, I edit some files (for example in a config file
> > "mock_data=true"), then I want to tag without commiting this change.
> 
> Tag applies to an existing commit [*1*].  Your change in the working tree
> is purely ephemeral until it is committed.
> 
> In other words, you don't "tag without committing".
> 
> > $ git tag -a v0.1 -m 'My v0.1 with mock data'
> 
> By omitting the [<head>] part from your command line for a command whose
> usage is:
> 
>   usage: git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]
> 
> you asked <head> to default to HEAD, the most recent commit, so the tag
> points at your 0ef41513d0b6 (This is the last commit).  The tag message
> should say "My v0.1" without anything else.
> 
> And show naturally shows the patch to bring its parent to that tagged
> commit.
> 
> If you wanted to keep your mainline pristine without mock data, and want
> to have a playpen that uses mock data, a way to do so is to use a separate
> branch, e.g.
> 
>         $ git checkout -b playpen
> 
> Now, you are on your 'playpen' branch that was forked from the tip of
> whatever branch you were on, perhaps 'master'.  Then commit that state
> with whatever change that is specific to the playpen you want to keep out
> of the mainline:
> 
> 	$ edit config.txt ;# set mock_data=true
>         $ git commit -a -m 'With mock data'
> 
> You can optionally tag the resulting commit if you want to.  You are still
> on the 'playpen' branch, so you probably would want to come back to the
> previous branch after you are done.
> 
> 
> [Footnote]
> 
> *1* technically, tag can apply to any type of object, but it is most
> common to apply to a commit.
> 
Andreas Schwab· Feb 24, 2012, 23:14 UTC · re: Romain Vimont (®om) · lore

Re: [Not A BugReport] git tag -a / git show

Romain Vimont "(®om)" <rom@rom1v.com> writes:
> To what other type of object can you apply a tag ?

Any. Take a look at the junio-gpg-pub tag in git's repository, or the v2.6.11-tree tag in Linus's kernel repository.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads