]> git.ipfire.org Git - thirdparty/git.git/commit
switch: make --orphan switch to an empty tree
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 29 Mar 2019 10:39:16 +0000 (17:39 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Apr 2019 04:57:00 +0000 (13:57 +0900)
commit1806c29f2eb5f7e4b5952f4fcc75f2afe279f1a4
treea3ae8668c6b94d37206498d73f6b95419f930fe5
parentc45f0f525de4701b8ff031d5c2c58c0fa819038e
switch: make --orphan switch to an empty tree

Switching and creating branches always involves knowing the
<start-point> to begin the new branch from. Sometimes, people want to
create a new branch that does not have any commits yet; --orphan is a
flag to allow that.

--orphan overrides the default of HEAD for <start-point> instead causing
us to start from an empty history with all tracked files removed from
the index and working tree. The use of --orphan is incompatible with
specifying a <start-point>.

A note on the implementation. An alternative is just create a dummy
commit in-core with empty tree and switch to it. But there's a chance
the commit's SHA-1 may end up somewhere permanent like reflog. It's best
to make sure "commit" pointer is NULL to avoid it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c