I have a a local, unpushed branch of a git repo. I am blocked from pushing my branch to origin cause I forgot to add in a ticket number in one of my git commit messages, so I can push to our master branch due to a restraint from our ticket integration.
The commit missing the ticket number is 3 commits pass my local branch head.
I've tried purposefully detaching at the commit to use --amend
but it did not work.
I've also tried to cherry-pick and --amend but that also did not work.
I've tried to do:
git reset [missing ticket # commit hash]
git commit --amend
and tried:
git cherry-pick [missing ticket # commit hash]
git commit --amend
Neither work.
3 Answers 3
You have do a rebase with interactive option. I.e:
git rebase --interactive HEAD~2
Then for the commit you want to change the message, choose the reword option.
1 Comment
HEAD~2 is specific to my case where the commit was 3 ahead.Just read a blog online to help. Was pretty dense and seemed outdated so I was very nervous of it.
But it worked.
git rebase --interactive [hash of parent commit]^
the carrot means to use as a parent and for every commit after it
then you'll be in some editor.
Change the word pick to one of the commands, in my case it was edit
Very important to do the instructions above. I was confused on how to edit. It's a simple text change.
Then you can use
git commit --amend
git rebase --continue
and now you should have the proper commit message.
TLDR:
git rebase --interactive [hash of parent commit]^
Edit pick on commit you want to change to edit
git commit --amend
git rebase --continue
3 Comments
git reword [commit hash] ? I have 2.17 and it was not there, unless that's not the proper way to use rewordgit rebase -i: change pick to reword instead of edit, and your next step is to fix the message—there's no faffing about with git commit --amend and git rebase --continue.With --amend flag you can change last commit message, e.g. git commit --amend -m "new commit message".
If you need to edit multiple commit massages use git rebase -i.
git rebase -i HEAD~10(pick a number > 3). Change the first column of the appropriate commit tor