忘了在git中分支,需要从主服务器移出更改 [英] Forgot to branch in git, need to move changes from master

查看:90
本文介绍了忘了在git中分支,需要从主服务器移出更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我热衷于进入代码模式并修改了一些文件,但是却忽略了从master分支.这些mod的范围并不广泛,以至于我无法重做它们,但是什么是将我(到目前为止,尚未提交的)master更改并迁移到新分支,而最终不影响master的好方法呢?

I eagerly ducked into code mode and modified some files, but neglected to branch from master first. The mods aren't so extensive that I can't redo them, but what's a good way of taking my (so far, uncommitted) changes in master and migrating them to a new branch, leaving master untouched in the end?

推荐答案

如果尚未提交任何内容(git status显示了一堆修改过的东西,也可以使用"git add" -ed):

If not yet committed anywhere (git status shows a bunch of stuff modified, it's OK if it's "git add"-ed too):

$ git checkout -b newbranch

尽管名称为checkout,但此用法(与-b一起使用)不会将任何内容检出. -b标志说创建一个新分支",因此git创建了分支名称并使其与当前HEAD提交相对应.然后,它使HEAD指向新分支,并在此处停止.

Despite the name checkout this usage (with -b) does not check anything out. The -b flag says "create a new branch", so git creates the branch-name and makes it correspond to the current HEAD commit. Then it makes HEAD point to the new branch, and stops there.

因此,您的下一个提交位于newbranch上,该文件作为您的父提交,即您开始修改文件时所处的提交.因此,假设您在master上,并且具有以下提交:

Your next commit is therefore on newbranch, which has as its parent commit, the commit you were on when you started modifying files. So assuming you were on master, and you had these commits:

A - B - C       <-- HEAD=master

checkout -b将其显示为:

A - B - C       <-- master, HEAD=newbranch

,随后的提交将添加新的提交D:

and a later commit adds a new commit D:

A - B - C       <-- master
          \
            D   <-- newbranch

这篇关于忘了在git中分支,需要从主服务器移出更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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