我在承诺信中写错了。

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


当前回答

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

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 重定向. 例如,如果您想要修改回来承诺 bbc643cd,运行

$ git rebase bbc643cd^ --interactive

在默认编辑器中,修改“选择”到“编辑”的行,您想要修改的承诺。

$ git add <filepattern>

现在你可以使用

$ git commit --amend

要改變承諾,然後

$ git rebase --continue

要回到前任首席执行官。

更改最新承诺消息

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 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-rebase-reword

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

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

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

例子:

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

对于任何正在寻找一个Windows/Mac GUI来帮助编辑旧消息(即不仅仅是最新消息),我会推荐Sourcetree。

此分類上一篇

对于尚未推到远程的承诺:

在“Log/History”选项卡中,右键单击您要编辑的承诺(s)下图中的附属线的输入,并选择“Rebase children of <commit ref> interactively..." 选择您要更改的承诺消息的整个行。

...或......对于已经推出的承诺:

遵循这个答案中的步骤,这些类似于上面的,但需要一个进一步的命令运行从命令线(git push 起源 <branch> -f) 强迫推分。