简体   繁体   English

使用基于功能分支的 rebase 提交消息修改,然后合并到 master

[英]Commit message amend using rebasing on feature branch and then merging into master

I have an old commit which was made on one old branch, say "old_branch_1".我有一个旧提交,它是在一个旧分支上进行的,比如“old_branch_1”。 This commit was merged into my "master" branch via a Pull Request.此提交通过拉取请求合并到我的“主”分支中。 Now I need to amend the message of that commit.现在我需要修改该提交的消息。 So I followed steps as below:所以我按照以下步骤操作:

  1. Created a new branch from "master", say "new_branch_1".从“master”创建了一个新分支,比如“new_branch_1”。
  2. Did checkout new_branch_1.是否结帐 new_branch_1。
  3. used git rebase -i HEAD~50 And then amended the required commit message.使用了 git rebase -i HEAD~50 ,然后修改了所需的提交信息。
  4. Once, rebase was completed.一次,rebase 就完成了。 I was a 100 commits ahead of remote and around 120 commits behind of remote.我在远程之前提交了 100 次,在远程之后提交了大约 120 次。
  5. Did git pull (and resolved the conflicts). git 是否拉动(并解决了冲突)。 Now I was 200 odd commits ahead.现在我提前了 200 次提交。
  6. Did git push. git 推送了吗?
  7. Now, I have raised a PR to my master branch.现在,我已经向我的 master 分支提出了 PR。

What I am not sure about is, whether post merging of PR, will it replace the old commit with new message or will it add this new commit to the top of master branch history.我不确定的是,无论是 PR 合并后,它会用新消息替换旧提交还是将这个新提交添加到主分支历史记录的顶部。

I really need to get rid of old commit message from the history.我真的需要从历史中删除旧的提交消息。 since the old message is causing issues when merging my code into production branches.因为在将我的代码合并到生产分支时,旧消息会导致问题。

TL;DR: The only way to get rid of the comment is to rebase and then force push. TL;DR:摆脱评论的唯一方法是变基然后强制推送。 That will most likely cause a lot of headaches if you're part of a team that has various topic branches currently in development.如果您所在的团队目前正在开发各种主题分支,那么这很可能会引起很多麻烦。

A rebase changes the commit IDs of every affected commit.变基会更改每个受影响提交的提交 ID。 After your rebase, you had the same number of commits as master at the time you branched off of it, but the most recent 50 had different commit ids.在你的 rebase 之后,你在分支时拥有与master相同数量的提交,但最近的 50 个提交 id 不同。 At that point you should have been 50 commits ahead and 50 behind master .那时,您应该提前 50 次提交,落后master 50 次。 Not sure how you wound up being 100 commits ahead.不确定你是如何提前 100 次提交的。 The additional "commits behind" could have occurred if other code had been merged into master between your checkout and the completion of your rebase.如果在结帐和完成 rebase 之间将其他代码合并到master中,则可能会发生额外的“提交延迟”。

When you merged master back into your branch, you brought back all 50 of those commits your rebase modified, including the commit messages.当您将master合并回您的分支时,您带回了所有 50 个您的 rebase 修改的提交,包括提交消息。 Your PR will not overwrite anything in the existing remote, but only add 50 more commits that are identical to the corresponding commits in your remote, with the exception that one of your new commits has a different comment message.您的 PR 不会覆盖现有远程中的任何内容,而只会再添加 50 个与远程中的相应提交相同的提交,除了您的一个新提交具有不同的评论消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM