git 批量提交_如何批量更新Git提交消息

本文介绍了如何在Mozilla中通过git自动批量更新提交消息,包括预先添加和追加消息到提交。作者分享了用于批量更新特定范围内每个提交消息的git命令。
摘要由CSDN通过智能技术生成

git 批量提交

At Mozilla we're mostly strict about receiving contributions via git/GitHub.  Aside from requiring tests and enforcing code quality, one basic of submitting a commit (or several) is that the commit message begins with "bug #######", which is a reference to its Bugzilla bug.  The message requirement makes sense but I hate going back to contributors and asking them to do "the paperwork" of changing their commit message to match our standard, so I generally try to make the update for them.

在Mozilla,我们非常严格地通过git / GitHub接收捐款。 除了要求测试和强制执行代码质量外,提交(或多次提交)提交的一个基本原则是,提交消息以“ bug #######”开头,这是对其Bugzilla Bug的引用。 消息需求是合理的,但是我讨厌回到贡献者那里,要求他们完成更改提交消息以符合我们的标准的“文书工作”,因此我通常会尝试为他们进行更新。

Recently MDN received a contribution which upgraded CKEditor and did so via approximately 60 commits, none of which referenced the bug number for the feature update.  I badly wanted to do the commit message updates for this contributor, but I wanted to do so in an automated way -- a batch update to save me the time updating each message one by one.  Welcome to filter-branch and --msg-filter!

最近,MDN收到了对CKEditor进行升级的贡献,并通过大约60次提交进行了升级,但没有一次引用功能更新的bug号。 我非常想为该贡献者进行提交消息更新,但是我想以一种自动化的方式进行-批量更新,以节省我逐个更新每条消息的时间。 欢迎使用filter-branch--msg-filter

预先提交消息 (Prepending to Commit Messages)

To prepend text to every commit message in a given range, you'd execute a message like:

要将文本添加到给定范围内的每个提交消息之前,请执行以下消息:


git filter-branch --msg-filter 'echo "bug ###### - \c" && cat' master..HEAD


The combination of filter-branch and --msg-filter will allow you to recurse through every commit message.  The echo piece allows you to build the new string.  The last piece is the range whose commit messages should be targeted -- in this case, I'm prepending the text to every commit in the feature branch.

filter-branch--msg-filter的组合将允许您遍历每个提交消息。 回声片段允许您构建新的字符串。 最后一部分是提交消息应该针对的范围-在这种情况下,我将文本放在feature分支中的每个提交之前。

You can also sed to achieve this:

您也可以通过sed实现:


git filter-branch -f --msg-filter 'sed "s/^/bug ###### - /"' master..HEAD


追加提交消息 (Appending to Commit Messages)

The case for appending to commit messages could be where you want to add the reviewer name(s) to the message.  Appending is roughly the same:

追加提交消息的情况可能是您要在消息中添加审阅者姓名的地方。 追加大致相同:


git filter-branch -f --msg-filter 'cat && echo "[Reviewer Walsh]"' master..HEAD


The difference here is the position of the cat command.  Everything else can be the same.

这里的区别是cat命令的位置。 其他所有内容都可以相同。

I have a love/hate relationship with git -- I love git because it's so easy for 90% of my needs but hate it when I need the other 10%.  Hopefully these examples help you if you run into this need in the future!

我与git有爱/恨关系-我喜欢git,因为它很容易满足我90%的需求,但讨厌我需要的另外10%。 如果将来遇到这种需求,希望这些示例对您有所帮助!

翻译自: https://davidwalsh.name/update-git-commit-messages

git 批量提交

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值