将现有的未提交的工作移至Git中的新分支 [英] Move existing, uncommitted work to a new branch in Git

查看:173
本文介绍了将现有的未提交的工作移至Git中的新分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了一些关于新功能的工作,经过编码后,我决定这个功能应该在它自己的分支上。



我如何将现有的未提交更改移动到新分支并重新设置当前分支?

我想要重新设置当前分支,同时保留现有的新功能。

解决方案

使用以下内容:

  git checkout -b  

这将使当前分支保持原样,创建并签出新分支并保留所有更改。然后你可以做一个提交:

  git add< files> 

并将其提交给您的新分支:

  git commit -m<此提交的简要描述> 

工作目录中的更改和索引中的更改不属于任何分支。这会改变这些更改的结束位置。



您不会重置原始分支,而是保持原样。最后一次提交< old-branch> 仍然是一样的。因此,您结帐-b 然后提交。


I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch.

How do I move the existing uncommitted changes to a new branch and reset my current one?

I want to reset my current branch while preserving existing work on the new feature.

解决方案

Use the following:

git checkout -b <new-branch>

This will leave your current branch as is, create and checkout a new branch and keep all your changes. You can then make a commit with:

git add <files>

and commit to your new branch with:

git commit -m "<Brief description of this commit>"

The changes in the working directory and changes staged in index do not belong to any branch yet. This changes where those changes would end in.

You don't reset your original branch, it stays as it is. The last commit on <old-branch> will still be the same. Therefore you checkout -b and then commit.

这篇关于将现有的未提交的工作移至Git中的新分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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