简体   繁体   English

在 GitHub 中编辑 git commit 消息

[英]Editing the git commit message in GitHub

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 pull and then git push has worked (without any other commit having interfered in the mean time).尝试git pull然后git push已经奏效(同时没有任何其他提交受到干扰)。

But can it be done via the GitHub website?但是可以通过GitHub网站完成吗?

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 --amend and press Enter.键入git commit --amend并按 Enter。
  3. In your text editor, edit the commit message and save the commit.在您的文本编辑器中,编辑提交消息并保存提交。
  4. Use the git push --force origin example-branch command to force push over the old commit.使用git push --force origin example-branch命令强制推送旧提交。

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

No, this is not directly possible.不,这不是直接可能的。 The hash for every Git commit is also calculated based on the commit message.每个 Git 提交的哈希值也是根据提交消息计算的。 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).如果要推送该提交,则必须强制该推送(git push -f)。 But if already someone pulled your old commit and started a work based on that commit, they would have to rebase their work onto your new commit.但是,如果已经有人撤回了您的旧提交并基于该提交开始了一项工作,那么他们将不得不将他们的工作重新定位到您的新提交上。

You need to git push -f assuming that nobody has pulled the other commit before.您需要git push -f假设之前没有人拉过其他提交。 Beware, you're changing history.当心,你正在改变历史。

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希望能帮助到你

No, because the commit message is related with the commit SHA / hash, and if we change it the commit SHA is also changed.不,因为提交消息与提交 SHA / 哈希有关,如果我们更改它,提交 SHA 也会更改。 The way I used is to create a comment on that commit.我使用的方式是对该提交创建评论。 I can't think the other way.我不能想别的办法。

For Android Studio / intellij users:对于 Android Studio / intellij 用户:

  • Select Version Control选择版本控制
  • Select Log选择日志
  • Right click the commit for which you want to rename右键单击要重命名的提交
  • Click Edit Commit Message单击编辑提交消息
  • Write your commit message写下你的提交信息
  • Done完毕

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.在您的 github 中查看特定分支,您将知道该分支中第一个提交的提交 ID。 do a rebase to that:做一个变基:

git rebase -i <Commit SHA of first commit>

an editor will open up.将打开一个编辑器。 Do a track of your commits from github UI and open editor and change the messages.从 github UI 跟踪您的提交并打开编辑器并更改消息。

I was asked to amend a patch commit message that I had submitted on github, (and ended up here.) This is what I did to get the job done.我被要求修改我在 github 上提交的补丁提交消息,(并最终在这里。)这就是我为完成工作所做的。

git clone git@github.com:YOURNAME/EXAMPLE.git; cd EXAMPLE; git fetch --all; git pull --all
git checkout -b patch-2 origin/patch-2 # create local patch-2 branch
git commit --amend # update the commit message
git push -f

This works for the last commit on a branch.这适用于分支上的最后一次提交。 If the commit in question is deeper you will need to do something more complicated.如果有问题的提交更深,您将需要做一些更复杂的事情。 (I don't know if the fetch and pull are needed, but I just past in that line while I work on something else to save time.) (我不知道是否需要 fetch 和 pull ,但我只是在做其他事情以节省时间时跳过那条线。)

For Visual Studio users:对于 Visual Studio 用户:

You are able to modify the commit message from the commit tab by clicking Unpushed Commit (1) and the View Outgoing/Incoming option (2).您可以通过单击 Unpushed Commit (1) 和 View Outgoing/Incoming 选项 (2) 从提交选项卡修改提交消息。 Then, once comment is modified (3), 'Amend Message' option (4) is enabled and changes are performed automatically in the commit.然后,一旦修改了评论 (3),“修改消息”选项 (4) 就会启用,并且会在提交中自动执行更改。

在此处输入图像描述

Tested on VS 2019在 VS 2019 上测试

可以通过 GitHub 网站完成吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM