从没有分支的分离提交中获取代码 [英] Getting back code from detached commit with no branch

查看:57
本文介绍了从没有分支的分离提交中获取代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不在分支中的提交,它包含我的所有最新工作.

I have a commit that is not in a branch and it contains all my latest work.

我需要将其添加到master分支.我怎样才能做到这一点?

I need to add it to the master branch. How can I do this?

git status显示以下内容:

* (detached from) b225b49
  master
  saved-work

如果我git checkout master,我会丢掉它吗?

Will I lose it if I git checkout master?

推荐答案

您处于git所说的分离头"状态.

You're in what git calls "detached HEAD" state.

有一种超级容易的恢复方法:

There's a super-easy way to recover:

git checkout -b newbranch

创建一个新分支newbranch,并在当前提交时将其放在上面(即,除了您现在位于名为newbranch的分支上之外,没有其他更改).然后,您可以在新分支上做任何您想做的事情(添加更多的提交,什么都可以),然后将其合并到其他分支中,或者您需要做的其他任何事情.

creates the new branch newbranch and puts you on it, at the current commit (i.e., nothing changes except that you're now "on" a branch named newbranch). You can then do whatever you like on the new branch (add more commits, whatever) and then merge it into some other branch, or whatever else you need to do.

这篇关于从没有分支的分离提交中获取代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆