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 +你想要创建的分支。

发现内容都还在,没有丢失。

发布了521 篇原创文章 · 获赞 94 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/bohu83/article/details/103825264