我在承诺信中写错了。

我怎么能改變訊息呢?承諾尚未推動。


当前回答

修正

这里有几种选择,你可以

git commit --amend

只要是你最后的承诺。

互动降落

否则,如果不是你的最后承诺,你可以做一个互动的折扣,

git rebase -i [branched_from] [hash before commit]

接下来,在互动的复制中,你只会添加编辑到这个承诺。当它出现时,做一个 git commit - 更改并修改承诺消息. 如果你想在这个承诺点之前旋转,你也可以使用 git reflog 并只会删除这个承诺。

其他回答

我更喜欢这样:

git commit --amend -c <commit ID>

否则,将有一个新的承诺与一个新的承诺ID。

如果您需要在多个分支上更改一个旧的承诺消息(即与错误消息的承诺存在于多个分支),您可能需要使用:

git filter-branch -f --msg-filter \
'sed "s/<old message>/<new message>/g"' -- --all

Git 将创建一个临时目录,以重新编写,并在 refs/original/中备份旧参考。

-f 将执行操作,这是必要的,如果临时目录已经存在,或者如果已经有参考存储在 refs/original 下,如果不是这样,你可以放下这个旗帜. -- 将过滤分支选项与审查选项分开。

由于您的旧参考备份,您可以在执行命令之前轻松地返回状态。

说,你想恢复你的主人,并在分支 old_master 中访问它:

git checkout -b old_master refs/original/refs/heads/master

更新您的最后一个错误的承诺消息与新的承诺消息在一个行:

git commit --amend -m "your new commit message"

或者,尝试 Git 重新设置如下:

# You can reset your head to n number of commit
# NOT a good idea for changing last commit message,
# but you can get an idea to split commit into multiple commits
git reset --soft HEAD^

# It will reset you last commit. Now, you
# can re-commit it with new commit message.

使用重新设置将命令分成较小的命令

git 重新设置可以帮助您将一个承诺分成多个承诺:

# Reset your head. I am resetting to last commits:
git reset --soft HEAD^
# (You can reset multiple commit by doing HEAD~2(no. of commits)

# Now, reset your head for splitting it to multiple commits
git reset HEAD

# Add and commit your files separately to make multiple commits: e.g
git add app/
git commit -m "add all files in app directory"

git add config/
git commit -m "add all files in config directory"

在这里,你成功地将最后的承诺分成两项承诺。

如果您正在使用 Git GUI 工具,则有一个按钮称为 修改最后的承诺. 点击该按钮,然后它将显示您的最后的承诺文件和消息. 只需编辑该消息,您可以承诺它一个新的承诺消息。

或使用此命令从控制台/终端:

git commit -a --amend -m "My new commit message"

我添加了 Aliases reci 和 recm for recommit (amend) 它. 现在我可以用 git recm 或 git recm -m:

$ vim ~/.gitconfig

[alias]

    ......
    cm = commit
    reci = commit --amend
    recm = commit --amend
    ......