Editing the git commit message in GitHub

GitGithubCommitPost Commit

Git Problem Overview


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

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).

But can it be done via the GitHub website?

Git Solutions


Solution 1 - Git

GitHub's instructions for doing this:

  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.
  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.

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

Solution 2 - Git

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, they would have to rebase their work onto your new commit.

Solution 3 - Git

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

Solution 4 - Git

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

  • Select Version Control
  • Select Log
  • Right click the commit for which you want to amend comment
  • Click reword
  • Done

Hope it helps

Solution 5 - Git

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.

Solution 6 - Git

For Android Studio / intellij users:

  • Select Version Control
  • Select Log
  • Right click the commit for which you want to rename
  • Click Edit Commit Message
  • Write your commit message
  • Done

Solution 7 - Git

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:

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.

Solution 8 - Git

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.

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.)

Solution 9 - Git

For Visual Studio users:

You are able to modify the commit message from the commit tab by clicking Unpushed Commit (1) and the View Outgoing/Incoming option (2). Then, once comment is modified (3), 'Amend Message' option (4) is enabled and changes are performed automatically in the commit.

enter image description here

Tested on VS 2019

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPNSView Question on Stackoverflow
Solution 1 - GitDan Green-LeipcigerView Answer on Stackoverflow
Solution 2 - GitdunniView Answer on Stackoverflow
Solution 3 - GitthreeView Answer on Stackoverflow
Solution 4 - GitSaurabh ValsangkarView Answer on Stackoverflow
Solution 5 - GitPrabowo MurtiView Answer on Stackoverflow
Solution 6 - GitMohamed AbdelraZekView Answer on Stackoverflow
Solution 7 - GitPriya JainView Answer on Stackoverflow
Solution 8 - GitAlexx RocheView Answer on Stackoverflow
Solution 9 - GitmggSoftView Answer on Stackoverflow