我已经提交了git并随后推送。我想更改提交消息。如果我理解正确,这是不可取的,因为在我进行此类更改之前,可能有人从远程存储库中删除了内容。如果我知道没人拉过呢?

有办法做到这一点吗?


当前回答

只需使用这两个命令即可更改上次推送的提交消息

-$gitcommit--modify-m“新提交消息。”-$git push—使用租约强制

其他回答

命令1您需要使用以下命令更改提交消息gitcommit--modify-m“新的正确消息”命令2添加新消息后,执行以下命令git push-f origin<your_branch_name>

案例1:未推送+最近提交:请参阅

案例2:已推送+最近提交:请参阅

案例3:未推送+旧提交:请参阅

案例4:已推送+旧提交:请参阅

我第一次尝试重命名已经推送的大约6条旧提交消息,之后我又做了进一步的提交。

因此,这是最糟糕的案例“案例4:已推送+旧提交”。

我是Vim(现在是Nvim)的用户,也是Vim《逃犯》的超级粉丝。所以我就是这样做的。

这是您在《逃犯》中关于重新定基的一般帮助:

Rebase maps ~

ri                      Perform an interactive rebase.  Uses ancestor of
u                       commit under cursor as upstream if available.

rf                      Perform an autosquash rebase without editing the todo
                        list.  Uses ancestor of commit under cursor as
                        upstream if available.

ru                      Perform an interactive rebase against @{upstream}.

rp                      Perform an interactive rebase against @{push}.

rr                      Continue the current rebase.

rs                      Skip the current commit and continue the current
                        rebase.

ra                      Abort the current rebase.

re                      Edit the current rebase todo list.

rw                      Perform an interactive rebase with the commit under
                        the cursor set to `reword`.

rm                      Perform an interactive rebase with the commit under
                        the cursor set to `edit`.

rd                      Perform an interactive rebase with the commit under
                        the cursor set to `drop`.

r<Space>                Populate command line with ":Git rebase ".

r?                      Show this help.

获取提交列表。:Git日志--单行我想修复第12行的提交消息(4d43a1b构建(MPL-402):editorconfigfixformesages.json),因为它不是正确的常规提交格式。我将光标放在提交哈希4d43a1b上,然后键入rw这将“在光标设置为reword的情况下执行一个交互式rebase和commit”。请注意,与gitrebase-i HEAD~X相比,这是多么好-知道X是什么并不是那么简单。现在,这将为您提供正确的gitrebase命令。所以用:wq写并退出缓冲区然后按照git/逃犯指导的步骤进行操作。我的一个提交出现了合并冲突,我通过正常的fugitve合并冲突过程解决了这个问题。

希望这足以让你度过第一个“我以前从未做过一次重新训练,我到底该做什么?”的难关。如果您需要后续步骤的帮助,请给我留言。

git commit --amend

然后在当前窗口中编辑和更改消息。在那之后

git push --force-with-lease

确保在正确的分支上进行更改

git checkout 

#确保您在正确的分支上进行更改只是为了确定:

git checkout branchname

Then

git commit --amend -m "new message"

然后按下

git push --force