git:将当前分支中当前未提交的正在进行的工作提交到新分支
有时我会发现自己处于以下情况: 我正在分支(比如主分支)上工作,并且正在编辑一些文件,但是当需要提交时,我意识到我更愿意提交到一个新分支(比如实验分支)。换句话说,旧分支(主分支)必须保持不变,并且应该创建一个新分支,如下所示:
.. -- master -- new commit
最简单的方法是什么?
目前,我提交旧分支,然后创建新分支,最后重置旧分支。但这真的很难看。
Occasionally I find my self in the following situation:
I am working on branch (say master) and I am editing some files, but when it comes the time for a commit I realize that I would prefer to commit to a new branch (say experimental). In other words, the old branch (master) must remain intact and a new branch should be created that will look like:
.. -- master -- new commit
What is the easiest way to do that?
Currently, I commit to old branch, then create the new branch and finally reset the old branch. But that's really ugly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您先创建新分支会稍微容易一些:
It's slightly easier if you create the new branch first:
另一种可能性是您继续将它们提交到
master
分支,然后从新的HEAD
中切断另一个分支(例如feature
) 。完成此操作后,您可以将 master 重置到提交之前的位置。Another possibility is for you to go ahead and commit them to the
master
branch, then cut off another branch from the newHEAD
(sayfeature
). Once this is done, you cangit reset
master to the position before the commits.