threads / discuss / 29424

Checkout tag?

Subject: Checkout tag?

## tl;dr

17 messages between Jan 22, 2012 and Jan 22, 2012.

replies: 16people: 5as markdown or json

Abscissa· Jan 22, 2012, 10:05 UTC · lore

I've managed to figure out you switch branches with the checkout command, like this:

>git checkout branch_name

Does that work for tags as well? The docs don't seem clear on that. If not, how do you get the working copy to be a specific tag?

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213023.html Sent from the git mailing list archive at Nabble.com.

Magnus Bäck· Jan 22, 2012, 10:11 UTC · re: Abscissa · lore

Re: Checkout tag?

On Sunday, January 22, 2012 at 11:05 CET,
     Abscissa <bus_nabble_git@semitwist.com> wrote:
Show 7 quoted lines
> I've managed to figure out you switch branches with the checkout
> command, like this:
> 
> >git checkout branch_name
> 
> Does that work for tags as well? The docs don't seem clear on that.
> If not, how do you get the working copy to be a specific tag?

Yes, "git checkout" works for branches, tags, commit SHA-1s, and anything else that can be resolved to a SHA-1 identifying what to check out. The git-checkout(1) man page says the following:

       git checkout [--patch] [<tree-ish>] [--] <pathspec>...
           ... The <tree-ish> argument can be used to specify a
           specific tree-ish (i.e. commit, tag or tree) ...
-- 
Magnus Bäck                   Opinions are my own and do not necessarily
SW Configuration Manager      represent the ones of my employer, etc.
Sony Ericsson
Abscissa· Jan 22, 2012, 10:25 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213061.html Sent from the git mailing list archive at Nabble.com.

Magnus Bäck· Jan 22, 2012, 11:31 UTC · re: Abscissa · lore

Re: Checkout tag?

On Sunday, January 22, 2012 at 11:25 CET,
     Abscissa <bus_nabble_git@semitwist.com> wrote:
Show 5 quoted lines
> I saw that, but it seems to imply that it's not a simple:
> 
> >git checkout tag_name
> 
> because of the required <pathspec>, whatever that is.

It isn't required. The part of the manual that I quoted (from Git 1.7.2.5) indicated that the pathspec is mandatory, but looking at the command synopsis at the top of the man page it's actually listed as optional.

Looking at an up to date Git 1.7.9-rc2 man page, it still seems slightly inconsistent with itself. The synopsis at the top says

      git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]
while the text in the DESCRIPTION section says
      git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...

The DETACHED HEAD section of the man page contains an example of checking out a tag, by the way.

If you're doubtful, why don't you just create a tag and try things out for yourself?

-- 
Magnus Bäck                   Opinions are my own and do not necessarily
SW Configuration Manager      represent the ones of my employer, etc.
Sony Ericsson
Jonathan Nieder· Jan 22, 2012, 17:08 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

Hi,
Magnus Bäck wrote:
Show 8 quoted lines
> Looking at an up to date Git 1.7.9-rc2 man page, it still seems
> slightly inconsistent with itself. The synopsis at the top says
>
>       git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]
>
> while the text in the DESCRIPTION section says
>
>       git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
Hmm, my copy says:
	SYNOPSIS
	git checkout [-q] [-f] [-m] [<branch>]
	git checkout [-q] [-f] [-m] [--detach] [<commit>]
	git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
	git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
	git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]
	DESCRIPTION
	... overview ...
	git checkout [<branch>], git checkout -b|-B <new_branch> [<start point>],
	git checkout [--detach] [<commit>]
		This form switches branches by updating the index, working
		tree, and HEAD...
	git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
		When <paths> or --patch are given, git checkout does not
		switch branches. It updates the named paths...

So in the synopsis it lists five forms, and in the description section it lists two forms, the first of which has three variants.

It's not immediately obvious to me which inconsistency you are pointing to as a source of confusion. Could you elaborate, preferably with suggested wording for a fix? If you can do so in the form of a patch, all the better. ;-)

Thanks, Jonathan

Magnus Bäck· Jan 22, 2012, 17:33 UTC · re: Jonathan Nieder · lore

Re: Checkout tag?

On Sunday, January 22, 2012 at 18:08 CET,
     Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 20 quoted lines
> Magnus Bäck wrote:
> 
> > Looking at an up to date Git 1.7.9-rc2 man page, it still seems
> > slightly inconsistent with itself. The synopsis at the top says
> >
> >       git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]
> >
> > while the text in the DESCRIPTION section says
> >
> >       git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
> 
> Hmm, my copy says:
> 
> 	SYNOPSIS
> 
> 	git checkout [-q] [-f] [-m] [<branch>]
> 	git checkout [-q] [-f] [-m] [--detach] [<commit>]
> 	git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
> 	git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
> 	git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]

Perhaps I wasn't clear -- I didn't mean that the synopsis *only* listed the form in my original quote above.

Show 21 quoted lines
> 	DESCRIPTION
> 
> 	... overview ...
> 
> 	git checkout [<branch>], git checkout -b|-B <new_branch> [<start point>],
> 	git checkout [--detach] [<commit>]
> 
> 		This form switches branches by updating the index, working
> 		tree, and HEAD...
> 
> 	git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
> 
> 		When <paths> or --patch are given, git checkout does not
> 		switch branches. It updates the named paths...
> 
> So in the synopsis it lists five forms, and in the description section
> it lists two forms, the first of which has three variants.
> 
> It's not immediately obvious to me which inconsistency you are
> pointing to as a source of confusion.  Could you elaborate,
> preferably with suggested wording for a fix?
I simply meant that
   git checkout [-p|--patch] [<tree-ish>] [--] [<paths>...]
   git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...

aren't identical even though I assume they describe the exact same scenario. The first command synopsis makes it clear that paths are optional while the second indicates that at least one path must be specified (unless "..." means "zero, one, or more occurences"). Also, "paths" != "pathspec".

> If you can do so in the form of a patch, all the better. ;-)

Sure, but it won't be during the coming week. Not that the patch is terribly difficult to prepare but because I need legal approval to submit it, and it's not clear I'll have time to deal with all that during my last week at work.

-- 
Magnus Bäck                   Opinions are my own and do not necessarily
SW Configuration Manager      represent the ones of my employer, etc.
Sony Ericsson
Abscissa· Jan 22, 2012, 10:26 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213063.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:26 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213066.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:27 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213069.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:27 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213072.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:28 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213074.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:28 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213076.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:29 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213078.html Sent from the git mailing list archive at Nabble.com.

Jakub Narebski· Jan 22, 2012, 11:30 UTC · re: Magnus Bäck · lore

Re: Checkout tag?

Magnus Bäck <magnus.back@sonyericsson.com> writes:
Show 14 quoted lines
> On Sunday, January 22, 2012 at 11:05 CET,
>      Abscissa <bus_nabble_git@semitwist.com> wrote:
> 
> > I've managed to figure out you switch branches with the checkout
> > command, like this:
> > 
> >   $ git checkout branch_name
> > 
> > Does that work for tags as well? The docs don't seem clear on that.
> > If not, how do you get the working copy to be a specific tag?
> 
> Yes, "git checkout" works for branches, tags, commit SHA-1s, and
> anything else that can be resolved to a SHA-1 identifying what to
> check out. [...]

Note however that because you can generate new commits only on top of local branches (refs/heads/*), if you check out something other than local branch, e.g.:

  $ git checkout v1.7.8
  $ git checkout origin/next
  $ git checkout HEAD^

you would be after such checkout in unnamed anonymous branch which contents corresponds to what you checked out. This state is called 'detached HEAD', and shows e.g. in "git branch output as

  $ git branch
  * (no branch)
  master
  ...

On the other hand if you don't want to checkout tag to explore it, but set contents of working area to the state it was in given tag, you can use

  $ git checkout v1.7.8 -- .
HTH

P.S. Instead of Nabble you can use GMane interface, or just use email (you don't have ot be subscribed to git@vger.kernel.org to post, and it is custom here to send replies also to author(s)).

-- 
Jakub Narebski
Nguyen Thai Ngoc Duy· Jan 22, 2012, 10:18 UTC · re: Abscissa · lore

Re: Checkout tag?

On Sun, Jan 22, 2012 at 5:05 PM, Abscissa <bus_nabble_git@semitwist.com> wrote:
Show 7 quoted lines
> I've managed to figure out you switch branches with the checkout command,
> like this:
>
>>git checkout branch_name
>
> Does that work for tags as well? The docs don't seem clear on that. If not,
> how do you get the working copy to be a specific tag?

Magnus already answered your checkout question. I just want to add that you can view a tag's content even without checking out. For example,"git archive" can create a zip/tarball of any tree-ish. "git ls-tree" lets you view directory structure of a tree-ish, "git show <tree-ish>:path" lets you view content of a specific file.

-- 
Duy
Abscissa· Jan 22, 2012, 10:29 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: Checkout tag?

I saw that, but it seems to imply that it's not a simple:
>git checkout tag_name
because of the required <pathspec>, whatever that is.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213081.html Sent from the git mailing list archive at Nabble.com.

Abscissa· Jan 22, 2012, 10:34 UTC · re: Abscissa · lore

Re: Checkout tag?

Sorry for the duplicates. Nabble kept crashing every time I tried to post, but I guess it was crashing after it posted to the mailing list.

-- View this message in context: http://git.661346.n2.nabble.com/Checkout-tag-tp7213023p7213090.html Sent from the git mailing list archive at Nabble.com.

← back to recent threads