0

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.

asked Mar 11, 2019 at 20:28
4

3 Answers 3

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.

answered Mar 11, 2019 at 20:33
Sign up to request clarification or add additional context in comments.

1 Comment

Found my answer already, but thanks! For anyone else HEAD~2 is specific to my case where the commit was 3 ahead.
2

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.

Helpful link

TLDR:

git rebase --interactive [hash of parent commit]^ 

Edit pick on commit you want to change to edit

git commit --amend
git rebase --continue
answered Mar 11, 2019 at 20:41

3 Comments

Note that "reword", if available, is much simpler. (It's not in some truly ancient Git versions, where you have to use the longer method that you used.)
so git reword [commit hash] ? I have 2.17 and it was not there, unless that's not the proper way to use reword
It's an option during git 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.
1

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.

answered Mar 12, 2019 at 9:28

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.