Change old commit message on Git

后端 未结 5 1118
南旧
南旧 2020-12-12 09:24

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 rebas

5条回答
  •  旧巷少年郎
    2020-12-12 09:54

    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:

    git checkout -b new-branch
    

    Then

    git merge --squash problem-branch
    git commit -m "new message" 
    

    Referece: https://github.com/rotati/wiki/wiki/Git:-Combine-all-messy-commits-into-one-commit-before-merging-to-Master-branch

提交回复
热议问题