如何创建一个新分支来清理另一个分支的提交?

发布于 2024-11-29 08:21:10 字数 570 浏览 0 评论 0原文

我有两个分支,masterfeature

我完成了 feature 的工作,因此这个分支有很多提交,但我不想按原样发布它。我想创建一个名为 feature_clean 的分支,其中包含来自 feature 的所有修改,但具有更好的提交。

我尝试了以下操作:

git checkout -b feature_clean master
git checkout feature
git rebase --interactive feature_clean
# reorganize commits etc, save and close editor

,这正确创建了 feature_clean 但它也修改了 feature。事实上,两个分支都是平等的。

我做错了什么?我想暂时保留 feature (在 feature_clean 经过适当测试和批准后,我将删除它)。

I have two branches, master and feature.

I finished working on feature, so this branch have a lot of commits, but I don't want to publish it as is. I want to create a branch called feature_clean with all the modifications from feature but with better commits.

I tried the following:

git checkout -b feature_clean master
git checkout feature
git rebase --interactive feature_clean
# reorganize commits etc, save and close editor

, and this created feature_clean correctly BUT it also modified feature. In fact, both branches were equal.

What did I do wrong? I want to keep feature as is for now (I'll delete it later, after feature_clean is appropriately tested and approved).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

家住魔仙堡 2024-12-06 08:21:10

你的 rebase 命令错误;)你告诉 git 在 feature_clean 之上重新设置当前分支(HEAD,在这种情况下为 feature) 。我认为您真正想要做的是:

git checkout -b feature_clean feature
git rebase -i master

即在 master 上重放来自 feature_clean 的提交。 feature 仍将指向旧的提交。

git rebase mastergit rebase --onto master master HEAD 的简写:获取 masterHEAD 之间的所有提交(可以从 HEAD 访问,但不能从 master 访问)并将它们粘贴到 master

you have your rebase command wrong ;) you are telling git to rebase the current branch (HEAD, in that case feature) on top of feature_clean. I think what you actually want to do is:

git checkout -b feature_clean feature
git rebase -i master

i.e. replay commits from feature_clean on master. feature will still point to the old commits.

git rebase master is shorthand for git rebase --onto master master HEAD: take all commits between master and HEAD (reachable from HEAD, but not from master) and stick them onto master

π浅易 2024-12-06 08:21:10
  1. 检查您的功能分支
    git checkout 功能

  2. 创建新的 feature_clean 分支
    git checkout -b feature_clean

  3. 将该分支重新设置为与 master 分离的位置
    git rebase -i --onto shaOfSplit shaOfSplit feature_clean

  4. 进行交互式变基

在变基结束时,您将从同一点断开两个分支。 feature_clean 将是 feature 的重新基础版本

  1. Checkout your feature branch
    git checkout feature

  2. Create your new feature_clean branch
    git checkout -b feature_clean

  3. Rebase that branch onto where you split off of master
    git rebase -i --onto shaOfSplit shaOfSplit feature_clean

  4. Do your interactive rebase

At the end of your rebase you will have two branches broken off from the same point. feature_clean will be a rebased version of feature

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文