正常的創建分支參見:git基於遠程master創建新分支
今天拉下來master,忘了拉分支,直接就改了commit了,然後push的時候失敗才發現。git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
怎麼把已經commit的內容不丟失,創建分支呢?
需要多加一步,回到對應commit上去。
git log
找到對應的commit log。
git checkout 141c517d5f94c17b0777
會提示:
ote: checking out '141c517d5f94c17b0777'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 141c517... commitmsg
在執行git checkout -b +你想要創建的分支。
發現內容都還在,沒有丟失。