116

Can one amend a git commit message using IntelliJ, or should one resort to command line?

How can this be done please?

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
James Raitsev
  • 92,517
  • 154
  • 335
  • 470

10 Answers10

99

View => Tool Windows => Version Control. (Windows (Alt + 9) / OS X (Cmd + 9))

IntelliJ 2017.1 and higher => Go to Log and right click + reword or press F2.

IntelliJ rename commit

While you are on the same branch, ( your checked out branch is the same )

Stefan Rein
  • 8,084
  • 3
  • 37
  • 37
  • 4
    This seems to be the only way (beside perhaps command line) to revise comments (without making a change to force a commit) with WebStorm 2017.3. This *Version Control* window appears via Alt+9, or View->Tool Windows->Version Control. – CODE-REaD Jan 18 '18 at 18:45
  • 3
    In Idea 2017.3 the described command is named "Reword..." instead of "Rename" (as shown in the screenshot :-) ). F2 also works. – Volker Seibt Jan 31 '18 at 08:20
  • 3
    Anyone an idea why "Edit Commit Message..." is greyed out in my IntelliJ (2019.3.1)? – Cold_Class Jan 07 '20 at 10:40
  • @Cold_Class Was this your commit message? I have one greyed out which is a merge. Like `Merge branch 'develop' of REPO_URL into BRANCH_NAME` is this what you mean? – Stefan Rein Jan 07 '20 at 11:58
  • @StefanRein - I was having this issue today and realised I Was in cherry pick mode - this has to be aborted – Lost Crotchet May 04 '20 at 10:10
  • 1
    @Cold_Class Mine was greyed out because I wasn't looking at the same branch as the one I had checked out. – Matthew Wilcoxson Jan 27 '22 at 10:27
74

Amend is supported: invoke "Commit Changes" and select the checkbox "Amend commit" in the Commit Dialog. Then press "Commit" button, and the commit will be amended to the previous one.

However, the support is limited:

  • you can't see the details of the commit being amended,
  • if you don't have any uncommitted changes (for example, you just want to change the message of the previous commit without adding more changes to it), you won't be able to invoke "Commit".
LoKi
  • 3,687
  • 2
  • 23
  • 16
  • 13
    Usual workaround against the second problem is adding some not-important characters (spaces etc) to a file so you'll be able to commit – leokom Oct 18 '14 at 16:48
  • JetBrains support referred me to enhancement requests [IDEA-81428](https://youtrack.jetbrains.com/issue/IDEA-81428) and [IDEA-57979](https://youtrack.jetbrains.com/issue/IDEA-57979). This question & answer are applicable to PyCharm too. – Wil Cooley Aug 06 '15 at 20:15
  • 10
    This answer is no longer true since 2017.2. You can do it easily now : `Version Control` panel > `Log` tab > select last commit > press F2. https://www.jetbrains.com/idea/whatsnew/#v2017-2-version-control – DLight Feb 26 '18 at 10:41
40

Finally found a workaround for this.. This issue was troubling me for days.

  1. Go to Version Control -Log tab
  2. Select the version, one below your changes. Right click and say "reset current branch to here"
  3. Select "Soft" and click on Reset, this is very important, you need to click on soft only so that your changes are not lost.
  4. Check in version control , local changes, your changes will be avialable in same changelist
  5. Right click on the change list and select commit.
  6. It will show you your previous commit message, now you can amend the comments and say commit and push

    Note: This solution uses android studio as intellij platform. 
    
Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
  • 1
    For me, in IntelliJ 17.3, I can use the "Reword... (F2)" menu item in the Version Control: Log to just edit the commit message directly. – Claes Mogren Feb 07 '18 at 01:36
32

You can also go to your git folder with a terminal and shell like powershell, cmd or bash (depends on your system), and then type:

git commit --amend -m "your new commit message"
Christopher J.
  • 1,154
  • 1
  • 12
  • 21
  • 3
    And since IntelliJ provides an integrated terminal, you don't even have to leave the IDE. This is probably the fastest way. – walen Oct 20 '16 at 13:55
  • How do you save the amend commit? I can't seem to figure out what is the exit command. CTRL-x CTRL-q? – JPM Aug 28 '20 at 22:04
  • there is ammend option while committin in intellij – Gaurav Aug 31 '20 at 16:23
15

Commit messages can be edited during a rebase. Invoke the Rebase command from the VCS menu, confirm the branch settings, then click the Rebase button. You'll be presented with a list of your unpushed commits. Choose the reword action from the drop-down to the left of the message you want to edit.

Check the git doc on Rewriting History for details on other rebase actions.

teppic
  • 7,051
  • 1
  • 29
  • 35
  • 2
    This is one of the better options. If you've already pushed your changes up to the origin, the IDE will warn you. This is a good thing, as if someone had already pulled the commit you pushed, amending the commit, even if just changing the commit message, will mean that everyone that had pulled the previous commit will also need to rebase. This is generally a "bad thing". – Chris Cogdon Mar 24 '16 at 18:39
3

In the Log tab, select the commit and press F2 (Reword). Thats it.

omilus
  • 1,176
  • 11
  • 9
3

In IntelliJ 2021.3 it's as simple as selecting the "Edit Commit Message..." menu drop down.

Screenshot of IntelliJ menu item

This is available in the Git Tool Window. And also in the Compare branch window if you have the same branch checked out, otherwise it's greyed out.

Matthew Wilcoxson
  • 3,432
  • 1
  • 43
  • 48
2

To be fair, the quickest way to do this is via the command line. I know the OP was asking about doing it via IntelliJ (Its how I found this question, I was trying to do it in PHPStorm), but seriously, its so much easier via the command line.

When in the correct folder in your terminal / command prompt type

git commit --amend

You'll then be shown the last commit message, simply edit the text and save the file, job done!

If you want to change the editor (it defaults to vi), then use this command, changing "vim" to your editor of choice.

git config --global core.editor "vim"

i.e. windows users may want to...

git config --global core.editor "notepad"

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

Steve Childs
  • 1,832
  • 2
  • 20
  • 26
  • 1
    Your answer is too similar to other ones, and brings even a less convenient method. `git commit --amend -m my_new_message` is used to change commit message directly from command line. – Christopher J. Jun 23 '17 at 06:45
  • I think this one is good. We can modify message based on the false message. And "VI" editor is good too. – Leo Lee Jun 28 '17 at 01:54
  • @ChristopherJ. - apologies, I didn't see your reply when I posted this. I'll leave it here though as i has the editor change addition if you don't like the default. – Steve Childs Jul 03 '17 at 12:08
2

In case, 2018.3 and same with 2017.1

Alt + 9 (version control window)

And right click -> context menu click "Reword... F2 "

OR

shorcut F2 You can edit message.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
redhot
  • 27
  • 6
0

In JetBrains Go to View -> Version Control -> This would open the version control log tab to the bottom of the screen Go to Log and you can see the commit that you did last Right click on it, and select undo commit

Bingo! You have reverted all your commit and the message is erased. You can also choose to do soft reset in case you only want to change the commit mesage

Emjey
  • 2,038
  • 3
  • 18
  • 33