我如何“移动"?我从“无分支"提交到一个实际的分支? [英] How do I "move" my commits from "no branch" to an actual branch?

查看:16
本文介绍了我如何“移动"?我从“无分支"提交到一个实际的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我犯了一个错误,开始提交到最后一个标签",这使我的提交落在无分支"中.它们应该已应用于现有分支的负责人.我还没有推送我的更改.我发现了其他一些关于何时提交位于 错误 分支的问题,但现在我没有 分支,所以我不知道如何处理.

最好,我想完全删除我的错误,并将我的更改移动"到正确分支的末尾.如果我必须将我的错误留在历史中,我至少需要将它们合并.

解决方案

您当前处于 分离的 HEAD 状态.要解决这个问题,您需要做的就是使用 git branch git checkout -b 创建一个新分支.这会给你留下一个你可以玩的本地分支,甚至在你完成后删除.

git 中的分支只是提交的指针,所以如果你创建一个新分支,你所在的新分支将指向你当前的提交,然后你可以合并它或诸如此类.>

您的错误"不需要被删除,您只需在以前的提交之上创建新的提交.您没有修改历史记录或类似内容.

为了回应您的评论,您需要做的是:

git branch tempgit checkout master # 或任何其他分支git合并临时git 分支 -d temp

I made a mistake, and started making commits "to the last tag", which lands my commits in "no branch". They should have been applied at the head of an already existing branch. I have not pushed my changes yet. I've found a few other question for when commits are in the wrong branch, but now I have no branch, so I don't know how to handle this.

Preferably, I would like to erase my mistake entirely, and "move" my changes to the end of the right branch. If I must leave my mistake in the history, I need to merge them in atleast.

解决方案

You are currently in a detached HEAD state. To resolve that, all you need to do is create a new branch with git branch <branchname> or git checkout -b <branchname>. That will leave you with a local branch you can play with, and even delete when you're done with it.

Branches in git are just pointers to commits, so if you create a new branch where you are the new branch will point to your current commit, and then you can merge it or whatnot.

Your "mistake" need not be erased, you simply created new commits on top of previous ones. You did not modify history or anything like that.

EDIT: In response to your comment, what you need to do is:

git branch temp
git checkout master # or any other branch
git merge temp
git branch -d temp

这篇关于我如何“移动"?我从“无分支"提交到一个实际的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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