追溯将Git提交行视为分支 [英] Retroactively treat line of Git commits as a branch

查看:85
本文介绍了追溯将Git提交行视为分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一堆问题问如何重写( rebase )一些提交,使它们出现在分支上,但是这些似乎都假设实际上需要重新设置,即分支所需的提交已散布在 master 上的所需提交(无论是您还是其他人所做的)。

A bunch of questions ask how to rewrite (rebase) some commits so that they appear on a branch, but these all seem to assume that rebase is actually necessary, i.e. that the commits wanted for the branch are interspersed with commits wanted on master (whether made by "you" or others).

这个问题很简单:我在 master 分支上有一个存储库的克隆,并且我做了很多打算创建GitHub pull请求的提交。通常我会运行

This question is simpler: I have a clone of a repository on the master branch, and I made a bunch of commits intending to create a GitHub pull request. Normally I would have run

git checkout -b new-feature

开始提交之前,但在这种情况下,我忘记了。我可以追溯地将此序列标记为在新分支上的提交(不需要使用 git rebase )吗?

before starting the commits, but in this case I forgot. Can I retroactively mark this sequence as commits as being on a new branch (without needing to use git rebase)?

推荐答案

您可以使用以下命令将提交移到分支并将主分支重置到原来的位置:

You can move the commits to a branch and reset your master branch to where it was with:

git branch new-feature
git reset --hard origin/master

请注意,这将删除所有未提交的更改,如果这是一个问题,则应在开始将其保存之前使用 git stash

Note that this will blow away any uncommitted changes, if that is a problem you should use git stash before starting to save them away.

这篇关于追溯将Git提交行视为分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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