pythongithubterminalpycharmedit

Is there a way to edit the descriptions of pushed commits on GitHub?


I'm using PyCharm, so the commit text inside of it saves from the last time you pushed a commit. I forgot to change the description of my new commit and accidentally pushed it without realizing that it was wrong. While not life-changing, this is certainly inconvenient and I'm not sure if there is an easy way to do this through GitHub. Help would be greatly appreciated!

Also, it's worthwhile to note that I have already moved on in my project, so the last commit is not the one with the mistake in it.

I tried looking around for any buttons in both PyCharm and GitHub, but could not find anything.


Solution

  • I forgot to change the description of my new commit and accidentally pushed it without realizing that it was wrong. [...] Also, it's worthwhile to note that I have already moved on in my project, so the last commit is not the one with the mistake in it.

    Looks like a job for rebase.

    I tried looking around for any buttons in both PyCharm and GitHub, but could not find anything.

    Not surprised. Rebasing is too powerful a feature to work within the confines of any GUI that I've seen. It also can be a footgun for the uninitiated.

    For this, you'll need to open a shell.

    # We're going to replace some commits in this branch, and in order to do that,
    # we first must switch to it.
    git checkout <your branch>
    # Note the "~" here -- it's necessary. It means "that commit ID, but the one
    # before it"
    git rebase -i <your commit id>~
    # Then:
    # 1. In the editor, change "pick" on the first line to "r" (reword)
    # 2. Save-exit the file
    # 3. The editor will immediately re-pop open with your commit message. Edit the
    # commit message, then save-exit the file.
    git rebase --continue
    git push -f
    

    This isn't recommended if you're part of a development team, but I've seen big open-source projects do it before.