重写主分支机构

发布于 2025-02-10 01:51:34 字数 688 浏览 1 评论 0原文

说我有这个犯罪历史:

A - B - C (master)
         \
          D - E - F (Feature)

我想修改pross b 。所以,我确实:

  • git Checkout Master
  • git rebase -i< hash的 a >

重新启动完成后,我看到使用GIT日志的更改。 但是,当我切换到功能分支时,提交 b 仍然与重新构想之前一样。 换句话说,当我在主人分支中时,提交历史如下:

A - B' - C (master)

当我切换到功能分支时,提交历史记录如下:

A - B - C (master)
         \
          D - E - F (Feature)

我知道重写提交历史并不明智,但在我的情况下我必须这样做。

我该如何修改旧的提交并在每个分支上反映这些更改? 我做错了吗?

新的提交历史将被迫将其推入Github,我不想把事情弄乱。

任何帮助将不胜感激。

Say I have this commit history:

A - B - C (master)
         \
          D - E - F (Feature)

I'd like to amend commit B. So, I do:

  • git checkout master
  • git rebase -i <hash of A>

After the rebase is done, I see the change using git log.
However when I switch to the Feature branch, commit B is still as it was before the rebase.
In other words, when I'm in master branch, the commit history looks like this:

A - B' - C (master)

When I switch to Feature branch, the commit history looks like this:

A - B - C (master)
         \
          D - E - F (Feature)

I understand that rewriting the commit history is not wise, but I have to do this in my case.

How can I amend an old commit and have those changes be reflected on every branch?
Am I doing this the wrong way?

The new commit history will be force pushed into Github and I don't want to mess things up.

Any help would be appreciated.

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

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

发布评论

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

评论(2

因为看清所以看轻 2025-02-17 01:51:34

重新构想后,您实际

  B'- C' (master)
 /
A - B - C
         \
          D - E - F (Feature)

现在已经完成了要完成操作,您必须重新安排功能 on(最近重写)master

$ git checkout Feature

$ git rebase master

          D'-E'-F' (Feature)
         /
A - B'- C' (master)
 \       
  B - C - D - E - F (soon to be garbage collected)

After your rebase, what you actually have is

  B'- C' (master)
 /
A - B - C
         \
          D - E - F (Feature)

So now to complete the operation you'd have to rebase Feature on (the recently rewritten) master

$ git checkout Feature

$ git rebase master

          D'-E'-F' (Feature)
         /
A - B'- C' (master)
 \       
  B - C - D - E - F (soon to be garbage collected)
记忆之渊 2025-02-17 01:51:34

并在每个分支上都反映了这些更改吗?

您需要手动重新重新置于每个分支机构。没有办法更改一个分支的内容,并将这些更改反映在其他分支上,这与GIT的工作方式相反。

and have those changes be reflected on every branch?

You need to manually rebase every branch. There is no way of changing the contents of one branch and have those changes be reflected on other branches, that is antithetical to how Git works.

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