在 GitHub 中编辑 git commit 消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10728420/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:45:48  来源:igfitidea点击:

Editing the git commit message in GitHub

gitgithubcommitpost-commit

提问by PNS

Is there any way of online editing the commit message in GitHub.com, after submission?

提交GitHub.com后,是否有任何在线编辑提交消息的方法?

From the command line, one can do

从命令行,可以做

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

as correctly suggested in another question.

正如另一个问题中正确建议的那样。

Trying git pulland then git pushhas worked (without any other commit having interfered in the mean time).

尝试git pull然后git push成功(同时没有任何其他提交干扰)。

But can it be done via the GitHubwebsite?

但是可以通过GitHub网站完成吗?

采纳答案by dunni

No, this is not directly possible. The hash for every Git commit is also calculated based on the commit message. When you change the commit message, you change the commit hash. If you want to push that commit, you have to force that push (git push -f). But if already someone pulled your old commit and started a work based on that commit, he would have to rebase his work onto your new commit.

不,这不是直接可能的。每个 Git 提交的哈希值也是根据提交消息计算的。当您更改提交消息时,您会更改提交哈希。如果你想推送那个提交,你必须强制推送(git push -f)。但是,如果已经有人拉取了您的旧提交并根据该提交开始了一项工作,则他将不得不将他的工作重新建立在您的新提交上。

回答by Dan Green-Leipciger

GitHub's instructions for doing this:

GitHub 的操作说明:

  1. On the command line, navigate to the repository that contains the commit you want to amend.
  2. Type git commit --amendand press Enter.
  3. In your text editor, edit the commit message and save the commit.
  4. Use the git push --force example-branchcommand to force push over the old commit.
  1. 在命令行上,导航到包含要修改的提交的存储库。
  2. 键入git commit --amend并按 Enter。
  3. 在文本编辑器中,编辑提交消息并保存提交。
  4. 使用该git push --force example-branch命令强制推送旧提交。

Source: https://help.github.com/articles/changing-a-commit-message/

来源:https: //help.github.com/articles/changed-a-commit-message/

回答by three

You need to git push -fassuming that nobody has pulled the other commit before. Beware, you're changing history.

你需要git push -f假设之前没有人拉过另一个提交。当心,你正在改变历史。

回答by Prabowo Murti

No, because the commit message is related with the commit SHA / hash, and if we change it the commit SHA is also changed. The way I used is to create a comment on that commit. I can't think the other way.

不,因为提交消息与提交 SHA/hash 相关,如果我们更改它,提交 SHA 也会更改。我使用的方法是对该提交创建评论。我不能反其道而行之。

回答by Saurabh Valsangkar

For intellij users:If you want to make changes in interactive way for past commits, which are not pushed follow below steps in Intellij:

对于 Intellij 用户:如果您想以交互方式对过去的提交进行更改,但未推送,请按照Intellij 中的以下步骤操作

  • Select Version Control
  • Select Log
  • Right click the commit for which you want to amend comment
  • Click reword
  • Done
  • 选择版本控制
  • 选择日志
  • 右键单击要修改评论的提交
  • 点击改写
  • 完毕

Hope it helps

希望能帮助到你

回答by Priya Jain

I was facing the same problem.

我面临同样的问题。

See in your github for a particular branch and you will come to know the commit id of the very first commit in that branch. do a rebase to that:

在您的 github 中查看特定分支,您将知道该分支中第一个提交的提交 ID。做一个rebase:

git rebase -i

git rebase -i

editor will open up. Do a track of your commits from github UI and opened editor and change the messages.

编辑器将打开。从 github UI 跟踪您的提交并打开编辑器并更改消息。