Почему git checkout --orphan <new_branch> <start_point>
приводит к созданию новой ветки, в которой все файлы в индексе <start_point>
добавляются к индексу <new_branch>
и готовы к фиксации?
Документация git checkout
(см. ниже) описывает семантику следующим образом:
Индекс и рабочее дерево настраиваются так, как если бы вы ранее запускали git checkout <start_point>
.
Обычно, когда я запускаю git checkout <branch>
, локальные изменения файлов в рабочем дереве сохраняются, поэтому их можно зафиксировать в <branch>
. Однако никакие файлы не добавляются автоматически в индекс ветки-сироты, как в случае с git checkout --orphan
. Где я могу увидеть эту деталь в документации?
Пример :
nlykkei@C02Y13AVJGH6:git-demo$ git init
Initialized empty Git repository in /Users/nlykkei/projects/demos/git-demo/.git/
nlykkei@C02Y13AVJGH6:git-demo (master #)$ echo HelloWorld > hello.txt
nlykkei@C02Y13AVJGH6:git-demo (master #%)$ git add hello.txt
nlykkei@C02Y13AVJGH6:git-demo (master +)$ git commit -m 'Added hello.txt'
[master (root-commit) 144ce8b] Added hello.txt
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
nlykkei@C02Y13AVJGH6:git-demo (master)$ git log
commit 144ce8be897ddf6618c6f6e94db67934356641f8 (HEAD -> master)
Author: nlykkei <nlykkei@gmail.com>
Date: Fri Jun 19 10:22:22 2020 +0200
Added hello.txt
nlykkei@C02Y13AVJGH6:git-demo (master)$ git status
On branch master
nothing to commit, working tree clean
nlykkei@C02Y13AVJGH6:git-demo (master)$ git checkout --orphan orphan_branch master
Switched to a new branch 'orphan_branch'
nlykkei@C02Y13AVJGH6:git-demo (orphan_branch +)$ git status
On branch orphan_branch
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello.txt
man git-checkout
:
--orphan <new_branch>
Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally
disconnected from all the other branches and commits.
The index and the working tree are adjusted as if you had previously run git checkout <start_point>. This allows you to start a new history that records a set of paths similar to <start_point> by easily
running git commit -a to make the root commit.