git - 如何重命名推送到 GitHub 的 Git 提交?

标签 git version-control github

我愚蠢地向 GitHub 提交了一个非常困惑的提交名称。我该如何更改?

git commit --amend 是否仍然适用于已推送的提交?

最佳答案

git commit --amend

这将调出你的编辑器,或者

git commit --amend -m "Your new message here"

这将允许您在命令行上指定新消息。也可能,但如果您有其他提交需要改写,则更有用

git rebase -i HEAD^
# then replace 'pick' with 'r' or 'reword' and save, editor should pop up again to edit the msg

由于此提交由于内容更改而具有新的 SHA1,因此您需要强制推送新引用。需要强制,因为它告诉 git 忘记之前的提交。这是一项安全措施。

git push origin your-branch-name -f

关于git - 如何重命名推送到 GitHub 的 Git 提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603473/

相关文章:

github - 调试 gist-vim

Git:如何查看在现在 merge 的分支上完成的工作

Git 撤消对文件的部分更改

Git 和 IntelliJ 行分隔符问题

svn - 你如何在svn中添加所有未跟踪的文件?像 git add -i 这样的东西?

android - 对 Google Play 控制台中的版本控制感到困惑

wordpress - github上的公共(public)密码

ruby-on-rails - 为什么 Bundler 找不到这个 gem?

git 接收包 : command not found

version-control - 想在 TortoiseHG/Mercurial 中为我的 .hgignore 文件创建一些默认值