如何重命名推送到 GitHub 的 Git 提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11603473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you rename a Git commit pushed to GitHub?
提问by adit
I stupidly pushed a commit to GitHub with a very messed up commit name. How do I change this?
我愚蠢地将提交提交到 GitHub,提交名称非常混乱。我该如何改变?
Does git commit --amend
still work for already pushed commit?
是否git commit --amend
还在为工作已经被推承诺?
回答by Adam Dymitruk
git commit --amend
which will bring up your editor, or
这将调出您的编辑器,或
git commit --amend -m "Your new message here"
which will allow you to specify the new message on the command line. Also possible, but more useful if you have other commits to reword
这将允许您在命令行上指定新消息。也有可能,但如果您有其他要改写的提交,则更有用
git rebase -i HEAD^
# then replace 'pick' with 'r' or 'reword' and save, editor should pop up again to edit the msg
Because this commit has a new SHA1 due to the change of the contents, you will need to force push the new reference. The force is needed because it tells git to forget about the previous commit. It's a safety measure.
因为这次提交由于内容的变化而有了新的 SHA1,所以你需要强制推送新的引用。需要强制,因为它告诉 git 忘记之前的提交。这是一项安全措施。
git push origin your-branch-name -f