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

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

问题描述

我犯了一个错误,并开始提交到最后一个标记,它将我的提交置于不分支。它们应该已经应用在一个已经存在的分支的头上。我 尚未推送我的更改。我发现了一些其他的问题,当提交时错误分支,但是现在我有了分支,所以我不知道如何处理这个。 / p>

最好,我想完全清除我的错误,并将我的更改移动到右分支的末尾。如果我必须在历史中遗漏我的错误,我需要至少将它们合并。

解决方案

您目前处于分离的HEAD 状态。为了解决这个问题,你需要做的就是用 git branch< branchname> git checkout -b< branchname>创建一个新分支。这会给你一个你可以玩的本地分支,甚至当你完成它时删除它。



git中的分支只是指针

em>提交,所以如果你创建了一个新的分支,那么你新建的分支将指向你当前的提交,然后你可以合并它或者其他东西。



你错误需要 not 被擦除,您只需在以前的提交之上创建新的提交。你没有修改历史或类似的东西。



编辑:作为对你的评论的回应,你需要做的是:

  git分支temp 
git checkout master#或任何其他分支
git合并temp temp $ b $ 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天全站免登陆