如何更改旧(本地)提交的消息?

这个问题在这里已经有了答案:

  • 如何修改现有的,未完成的提交? 27个答案

  • 交互式底git rebase -i 637bd5ac^通常是最简单的方法: git rebase -i 637bd5ac^

    这将在每行提交之后打开编辑器,因为在一行中提到了这个提交。 对于每个提交,您可以选择要如何修改它; 选择(保持原样),编辑,reword(仅编辑提交消息),压扁(将前一个提交与一个提交和一个提交消息合并)或fixup(像squash,但忽略第二个提交消息)。 您也可以在执行此操作时重新排序或删除提交。

    对于你的问题,你会想要选择“reword”作为提交的问题,那么你将有机会编辑该消息。


    git commit -amend只能改变最后一次提交。 你应该使用git rebase -i在提交历史记录中选择并编辑你的提交。


    我想更改Make sidenav组件的提交消息。
    我想过使用git commit -ammend但我认为它只能用于更改最后一次提交的消息?

    git commit -ammend

    这只会更新你的HEAD ,这是最新的提交信息。
    如果你想更新链中的其他消息,你有几个选择:


    Interactive rebase = git rebase -i HEAD~X

    找到你想要的提交,将选择改为eedit ),然后保存并关闭文件。

    现在当git停在所需的提交上时,请使用git commit --amend来进行更改。


    git filter-branch

    这里也有几个选项。 什么git filter-branch循环的提交集并按照你告诉它的方式更新它们。

    例如你可以使用这一行来更新所需的字符串:

    git filter-branch -f --msg-filter 'sed "s/...//g"' -- --all
    

    或者这个脚本(这个修改了提交者数据)

    # Loop over all the commits and use the --commit-filter
    # to change only the email addresses
    
    git filter-branch --commit-filter '
    
        # check to see if the committer (email is the desired one)
        if [ "$GIT_COMMITTER_EMAIL" = "<Old Email>" ];
        then
                # Set the new desired name
                GIT_COMMITTER_NAME="<New Name>";
                GIT_AUTHOR_NAME="<New Name>";
    
                # Set the new desired email
                GIT_COMMITTER_EMAIL="<New Email>";
                GIT_AUTHOR_EMAIL="<New Email>";
    
                # (re) commit with the updated information
                git commit-tree "$@";
        else
                # No need to update so commit as is
                git commit-tree "$@";
        fi' 
    HEAD
    

    链接地址: http://www.djcxy.com/p/1403.html

    上一篇: How to change the message of an old (local) commit?

    下一篇: Change the wrong commit message in Git