git:更改旧的提交消息而不会产生冲突 [英] git: changing an old commit message without creating conflicts

查看:79
本文介绍了git:更改旧的提交消息而不会产生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下命令更改很旧的提交消息:

I want to change a pretty old commit message using:

git rebase -i sha1-of-commit^

很好,我会执行 git commit --amend 并编辑消息,但是当我这样做时情况会变糟:

That's nice, I do git commit --amend and edit the message, but things get bad when I do:

git rebase --continue

我遇到了多个冲突,但不明白为什么整个冲突解决方案过去显然已经完成了,所以git应该移动前进,直到所有提交都重新基准化为止。

I encounter multiple conflicts but don't understand why as the whole conflict resolution has obviously already been done in the past, and git should just move forward until all commits are rebased.

如何在不处理这些旧冲突的情况下快速完成变基?我只想更改一条简单(旧的)提交消息毕竟...

How can I finish the rebase quickly without having to handle these old conflicts? I just want to change a simple (and old) commit message after all...

推荐答案

在您的 / bin 名为 git-reword-commit 的目录(或路径中的任何目录)。 (您可以随意命名,只要名称以 git-开头。无论是否有合并提交,此方法都可以使用。

Make a small script in your /bin directory (or any directory in your path) named git-reword-commit. (You can name it whatever you want as long as the name starts with git-. This will work regardless of whether there are merge commits or not.

#! /bin/bash
REV=$1
MESSAGE=$2
FILTER="test $(echo '$GIT_COMMIT') = $(git rev-parse $REV) && echo $MESSAGE || cat"
git filter-branch --msg-filter "$FILTER" -- --all

要使用,执行

git reword-commit <commit> 'new message'

警告: 这将重写许多提交,因此适用于变基的问题也同样适用于此,即,您在推送时需要强行使用,其他用户必须知道这一点。

Warning: This will rewrite many commits, so the same issues that apply to rebase, apply here as well, i.e., you will need to force when you push, and other users will have to know about this.

Git将您的原始裁判(来自过滤器分支之前)放在 .git / refs / original 中,您可以使用以下别名

Git puts your original refs (from before the filter-branch) in .git/refs/original. You can use the following aliases to undo/confirm any filter-branch command.

git config alias.undo-filter-branch '! DIR=$(git rev-parse --git-dir); cp -r $DIR/refs/original/refs/ .git/; rm -r $DIR/refs/original/'
git config alias.confirm-filter-branch '! DIR=$(git rev-parse --git-dir); rm -r $DIR/refs/original/'

这篇关于git:更改旧的提交消息而不会产生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆