How to modify one commit in Git when multiple commits share the same Jira ticket

Feature branch has two commits for one Jira ticket. I need to update only the second commit. What Git method should I use? Here is a log sample:

commit 9abc (HEAD -> branch/TICKET123, origin/branch/TICKET123)
Author: alice
Date: 02/01/2024
Feature update and refactor

commit def0
Author: alice
Date: 02/01/2024
Cleanup changes

hey, try an interactive rebase: git rebase -i HEAD~2, change pick to edit for the second commit then amend. force push after. works fine in most cases

One effective solution is to manually rewrite the commit history by using a reset rather than relying on interactive rebase. I encountered a scenario where I had to modify an earlier commit and decided to reset the branch to just before that commit. By performing a soft reset, all the changes remained staged, allowing me to selectively adjust the desired modifications. Once the changes were amended, I committed them with the updated message and reapplied the subsequent commit. This method, although a bit more involved, gave me greater control over the process and helped to keep the branch history clean. It is advisable to backup your branch prior to making such changes.

hey, i got it working using git commit --fixup and then autosquash rebase with git rebase -i --autosquash HEAD~2. neat method that auto-merges the fix. don’t forget to force push!

In my experience, using an interactive rebase is a reliable option. I typically start with git rebase -i and then change the command for the commit I need to modify from pick to edit. This allows me to temporarily pause the process and adjust the commit. After performing git commit --amend to update the commit as needed, I then continue the rebase. Remember that when rewriting history, you have to force push the branch, so it’s important to ensure that the branch isn’t widely used by others before taking this approach.