我在承诺信中写错了。

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


当前回答

修正

这里有几种选择,你可以

git commit --amend

只要是你最后的承诺。

互动降落

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

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

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

其他回答

如果您正在使用 Git GUI,您可以更改未被推的最后一个承诺:

Commit/Amend Last Commit

更改最新承诺消息

git commit --amend

git commit --amend -m "New commit message"

...任何人,这可能会使多线承诺消息或小纠正更有吸引力进入。

确保您在做此之前没有任何工作复制变更,或者它们也会被承诺(未进行的变更不会被承诺)。

git push <remote> <branch> --force
# Or
git push <remote> <branch> -f


// n is the number of commits up to the last commit you want to be able to edit
git rebase -i HEAD~n

一旦你错过了你的承诺,选择e/r来编辑消息:

如果你使用 git rebase -i HEAD~n 可以有更多的 n 命令. Git 将“收集”最后 n 命令中的所有命令,如果在这个范围之间有某个合并,你会看到所有的命令,所以结果将是 n + 。

好提示:


git-commit(1) 手动 页 git-rebase(1) 手动 页 git-push(1) 手动 页

您可以使用 git-rebase-reword

它旨在以同样的方式编辑任何承诺(不只是最后) - 修改

$ git rebase-reword <commit-or-refname>

它被命名为反对互动的行动,以改变一个承诺:“反对”。 查看此帖子和人 - 部分互动模式-

例子:

$ git rebase-reword b68f560
$ git rebase-reword HEAD^

如果这是你的最后承诺,只需修改承诺:

git commit --amend -o -m "New commit message"

如果这是一个埋葬的承诺,使用令人惊叹的互动折叠:

git rebase -i @~9   # Show the last 9 commits in a text editor


运行 vimtutor 如果你有时间 hjkl 匹配运动密钥 ← ↓ ↑→ 所有命令都可以用“范围”预定,例如 3j 移动下三个行 i 输入输入模式 - 文本你输入将显示在文件 Esc 或 Ctrlc 输出输入模式和返回“正常”模式 u 到 undo Ctrlr 重定向 dd, dw, dl 删除一个行,字,或字母, 相应 cc, cw, cl 更改一个行,字母,或字母, re

如果你编辑了很多文本,然后转到Dvorak键盘配置,学习触摸类型,并学习Vim。

此分類上一篇


ProTipTM: 不要害怕使用重写历史的“危险”命令进行实验* - Git 不会默认删除您的订单 90 天; 您可以在重写中找到它们:

$ git reset @~3   # Go back three commits
$ git reflog
c4f708b HEAD@{0}: reset: moving to @~3
2c52489 HEAD@{1}: commit: more changes
4a5246d HEAD@{2}: commit: make important changes
e8571e4 HEAD@{3}: commit: make some changes
... earlier commits ...
$ git reset 2c52489
... and you're back where you started

我使用Git GUI尽我所能,这给了你更改最后的承诺的选项:

此分類上一篇

此外, git rebase -i 起源/masteris 一个可爱的 mantra 将始终向您介绍您在主人的顶部所做的承诺,并为您提供更改、删除、重新订单或破坏的选项。