git基於commit創建分支

正常的創建分支參見: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 +你想要創建的分支。

發現內容都還在,沒有丟失。

發佈了505 篇原創文章 · 獲贊 84 · 訪問量 53萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章