git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Where is git checkout --orphan implemented at.
@ 2018-06-05 16:02 Sean Hunt
  2018-06-05 17:54 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Hunt @ 2018-06-05 16:02 UTC (permalink / raw)
  To: git

I would like to see the source code to git checkout --orphan so I can learn how it works and so I can manually do what it does by hand on making a new branch with no history in the refs folder. I can only do it on my iPhone as my laptop has no internet or way to do it there, and the program on my iPhone does not have the method implemented yet visually to do it, forcing manual creation of the orphan branch by hand in the end. If the public github had all the codes to all commands and subcommands like the one above it would be nice or well at least a file that explains the source file each command and subcommands are from so that way a person like me can use as a reference to make our own git gui that has 100% of command line git features.

Sent from my iPhone

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is git checkout --orphan implemented at.
  2018-06-05 16:02 Where is git checkout --orphan implemented at Sean Hunt
@ 2018-06-05 17:54 ` Jeff King
  2018-06-11 17:35   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2018-06-05 17:54 UTC (permalink / raw)
  To: Sean Hunt; +Cc: git

On Tue, Jun 05, 2018 at 12:02:12PM -0400, Sean Hunt wrote:

> I would like to see the source code to git checkout --orphan so I can
> learn how it works and so I can manually do what it does by hand on
> making a new branch with no history in the refs folder. I can only do
> it on my iPhone as my laptop has no internet or way to do it there,
> and the program on my iPhone does not have the method implemented yet
> visually to do it, forcing manual creation of the orphan branch by
> hand in the end. If the public github had all the codes to all
> commands and subcommands like the one above it would be nice or well
> at least a file that explains the source file each command and
> subcommands are from so that way a person like me can use as a
> reference to make our own git gui that has 100% of command line git
> features.

The code for "checkout --orphan" is in builtin/checkout.c[1].

But if you want to do roughly the same thing with other tools, you can
do:

 git symbolic-ref HEAD refs/heads/new-branch

If you don't even have symbolic-ref handy, you can do:

  echo "ref: refs/heads/new-branch" >.git/HEAD

That's not generally recommended, since future versions of Git may
change the ref storage format, but it would work with any current
version of Git.

-Peff

[1] Try update_refs_for_switch(), especially:

    https://github.com/git/git/blob/61856ae69a2ceb241a90e47953e18f218e4d5f2f/builtin/checkout.c#L635

    and

    https://github.com/git/git/blob/61856ae69a2ceb241a90e47953e18f218e4d5f2f/builtin/checkout.c#L695

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is git checkout --orphan implemented at.
  2018-06-05 17:54 ` Jeff King
@ 2018-06-11 17:35   ` Junio C Hamano
  2018-06-11 21:09     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2018-06-11 17:35 UTC (permalink / raw)
  To: Jeff King; +Cc: Sean Hunt, git

Jeff King <peff@peff.net> writes:

> If you don't even have symbolic-ref handy, you can do:
>
>   echo "ref: refs/heads/new-branch" >.git/HEAD
>
> That's not generally recommended, since future versions of Git may
> change the ref storage format, but it would work with any current
> version of Git.

Makes one wonder if it really "works" if .git/HEAD was created by
older version of Git or in a repository where prefer-symlink-refs is
enabled, though ;-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is git checkout --orphan implemented at.
  2018-06-11 17:35   ` Junio C Hamano
@ 2018-06-11 21:09     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2018-06-11 21:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sean Hunt, git

On Mon, Jun 11, 2018 at 10:35:40AM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > If you don't even have symbolic-ref handy, you can do:
> >
> >   echo "ref: refs/heads/new-branch" >.git/HEAD
> >
> > That's not generally recommended, since future versions of Git may
> > change the ref storage format, but it would work with any current
> > version of Git.
> 
> Makes one wonder if it really "works" if .git/HEAD was created by
> older version of Git or in a repository where prefer-symlink-refs is
> enabled, though ;-)

Heh, true. I guess "rm -f .git/HEAD" before would "fix" it.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-11 21:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-05 16:02 Where is git checkout --orphan implemented at Sean Hunt
2018-06-05 17:54 ` Jeff King
2018-06-11 17:35   ` Junio C Hamano
2018-06-11 21:09     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).