我在承诺信中写错了。

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


当前回答

我意识到我已经推着一个承诺与一个类型在其中。为了放弃,我做了以下事情:

git commit --amend -m "T-1000, advanced prototype"
git push --force

警告:强迫推你的变化将重新写下远方分支与你的当地一个. 确保你不会过度写下任何你想保持的东西. 也要小心强迫推一个修改(重新写)承诺,如果其他人与你分享分支,因为他们将需要重新写下自己的历史,如果他们有旧的副本的承诺,你刚刚重新写。

其他回答

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

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 commit --amend -m "your new message"

如果你想修正的承诺不是最新的承诺:

git rebase --interactive $parent_of_flawed_commit 如果你想修复几个错误的命令,通过最古老的命令的父母。 一个编辑会出现,从你给的所有命令的列表。 更改选择重新命令(或在旧版本的Git,编辑)在任何命令你想修复的前面。 一旦你保存,Git将重新播放列出的命令。

它是非常容易的;你不需要记住它 - 只是记住, git rebase - 互动允许你纠正命令,无论他们是多久以前。


请注意,你不会想改变你已经推的承诺,或者也许你会这样做,但在这种情况下,你将不得不非常小心地与任何可能推你的承诺并完成工作。

修正

这里有几种选择,你可以

git commit --amend

只要是你最后的承诺。

互动降落

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

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

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

您可以使用 git-rebase-reword

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

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

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

例子:

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