2

I inadvertently committed code without a JIRA ticket in the commit message and I am not able to push any code. In the past if this happened, I used the "Amend last commit" feature in source tree, but this is a different situation, where the faulty commit was two commits back, so I am not able to figure out how to add the JIRA issue ticket to that commit. To explain the issue a bit further, here's an example

  • Commit 1 Message (did something)
  • Commit 2 Message (did something again JIRA-123)

How do I fix "Commit 1 Message" to have an issue? Is there another way to resolve this? Thanks!

Seagull
  • 2,219
  • 6
  • 25
  • 33

2 Answers2

1

If you want to edit a commit message you can do it as part of an interactive rebase. But do it with caution, so you don't end up messing up your repo. It can be a good idea to branch out first, to have a backup branch.

In Sourcetree:

  1. Right click a commit that's older than the one you want to edit, and choose "Rebase children of xxxx interactively...". The one you click will be your "base" and you can make changes to every commit made after that one.
  2. In the new window, select the commit you want to edit, and press the "Edit Message"-button at the bottom, or simply double click the commit.
  3. Edit the message, and click "OK"
  4. Click "OK" (or "Cancel" if you want to abort).

Check out this Atlassian blog post for more on interactive rebasing in Sourcetree.

jna
  • 926
  • 10
  • 18
0

Assuming you haven't pushed yet: Use "interactive rebase" (git rebase -i). this will bring up an editor where you can mark that 1st commit as reword, then you'll get a second editor where you can edit the commit message.

Matt McHenry
  • 20,009
  • 8
  • 65
  • 64
  • For some reason that particular change list is not showing up in the list of past commits. I do want to point out that this particular commit that's not showing up was a merge of the "master" branch to another branch (originally branched from the master) – Seagull Nov 21 '17 at 02:43
  • A rebase wouldn't do it for me, so I went ahead and essentially did a reset to a prior commit :-( – Seagull Nov 21 '17 at 03:11