I was trying to edit an old commit message as explained here.
The thing is that now, when I try to run rebase -i HEAD~5
it says interactive rebase already started
.
So then I try: git rebase --continue
but got this error:
error: Ref refs/heads/master is at 7c1645b447a8ea86ee143dd08400710c419b945b but expected c7577b53d05c91026b9906b6d29c1cf44117d6ba
fatal: Cannot lock the ref 'refs/heads/master'.
Any ideas?
Here's a very nice Gist that covers all the possible cases: https://gist.github.com/nepsilon/156387acf9e1e72d48fa35c4fabef0b4
Overview:
It says:
It does not mean:
Try to not typing
git rebase -i HEAD~3
when exiting the editor, and it should work fine.(otherwise, in your particular situation, a
git rebase -i --abort
might be needed to reset everything and allow you to try again)As Dave Vogt mentions in the comments,
git rebase --continue
is for going to the next task in the rebasing process, after you've amended the first commit.Also, Gregg Lind mentions in his answer the
reword
command ofgit rebase
:Just wanted to provide a different option for this. In my case, I usually work on my individual branches then merge to master, and the individual commits I do to my local are not that important.
Due to a git hook that checks for the appropriate ticket number on Jira but was case sensitive, I was prevented from pushing my code. Also, the commit was done long ago and I didn't want to count how many commits to go back on the rebase.
So what I did was to create a new branch from latest master and squash all commits from problem branch into a single commit on new branch. It was easier for me and I think it's good idea to have it here as future reference.
From latest master:
Then
Referece: https://github.com/rotati/wiki/wiki/Git:-Combine-all-messy-commits-into-one-commit-before-merging-to-Master-branch
FWIW, git rebase interactive now has a "reword" option, which makes this much less painful!
You can do this following way as @gregg said to use word reword
Here n is the list of last n commits.
For example if you use
git rebase -i HEAD~4
Now replace word pick with reword for commit you want to edit message.
Now close and save this you will get chance to edit commit message for which you have used reword in following windows.
You can refer official document here as well