当我做了导致分离头部的签出,git实际上告诉我在这种情况下该怎么做:
Git开关-c \<new-branchname>
结果会像分离头之前一样离开主节点,而包含在分离头状态下工作时所做的所有提交的新分支。
重现/测试/了解更多细节:
用两次提交创建一个testrepo:
~/gittest$ git log——一行
17c34c0 (HEAD -> master
5975930 1
签出之前的提交1
~/gittest$ git checkout 5975930
这条德国信息出现了
Hinweis: Wechsle zu '5975930'.
Sie befinden sich im Zustand eines 'losgelösten HEAD'. Sie können sich
umschauen, experimentelle Änderungen vornehmen und diese committen,
und Sie können alle möglichen Commits, die Sie in diesem Zustand
machen, ohne Auswirkungen auf irgendeinen Branch verwerfen, indem Sie
zu einem anderen Branch wechseln.
Wenn Sie einen neuen Branch erstellen möchten, um Ihre erstellten
Commits zu behalten, können Sie das (jetzt oder später) durch Nutzung
von 'switch' mit der Option -c tun. Beispiel:
git switch -c \<neuer-Branchname>
Oder um diese Operation rückgängig zu machen: git switch -
Sie können diesen Hinweis ausschalten, indem Sie die
Konfigurationsvariable 'advice.detachedHead' auf 'false' setzen.
HEAD ist jetzt bei 5975930 1
翻译成英语是:
Note: Change to '5975930'.
You are in the state of a 'detached HEAD'. You can look around, make experimental changes and commit them, and you can discard any
possible commits you make in this state without affecting any branch
by switching to another branch.
If you want to create a new branch to keep your created commits, you can do that (now or later) by using 'switch' with the -c option.
Example:
git switch -c <new-branch-name>.
Or to undo this operation: git switch -.
You can turn off this hint by setting the configuration variable 'advice.detachedHead' to 'false'.
HEAD is now at 5975930 1
(通过www.DeepL.com/Translator翻译(免费版))