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

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

问题描述

我犯了一个错误,并开始向最后一个标签"提交提交,这使我的提交落入无分支".它们应该已经应用在已经存在的分支的头上.我 not 还没有推送我的更改.我还发现了其他一些关于何时在错误分支中提交内容的问题,但是现在我有了 no 分支,所以我不知道该如何处理. /p>

最好,我想完全消除我的错误,并将更改移动"到右分支的末尾.如果我必须将自己的错误遗忘在历史中,则需要至少合并它们.

解决方案

您当前处于<​​strong>分离的HEAD 状态.要解决此问题,您所需要做的就是使用git branch <branchname>git checkout -b <branchname>创建一个新分支.这样一来,您将拥有一个可以玩的本地分支,甚至在使用完毕后也可以删除.

git中的分支只是要提交的指针,因此,如果您在其中创建新分支,则新分支将指向您的当前提交,然后您可以将其合并. >

无需删除您的错误",只需在先前提交的基础上创建新的提交即可.您没有修改历史记录或类似的内容.

针对您的评论,您需要做的是:

git branch temp
git checkout master # or any other branch
git merge temp
git branch -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天全站免登陆