0

All I need to do is modify the commit message of some past commits in my branch locally, then push those modifications up to the server. I don't need to actually change any files in the past commits, and the past commits are not the most recent, they're from 2-3 commits ago.

Most answers I've seen deal with either modifying the files of past commits, or else just modifying the most recent commit message. Neither is quite what I'm looking for.

I'm hoping this is a quick and easy one for all you git experts :-)

gzak
  • 3,908
  • 6
  • 33
  • 56
  • the title of that other question really should be edited since the bulk of it has to do with pushed commits... id say this there but its a locked thread. – UpAndAdam Oct 06 '16 at 22:16

1 Answers1

1

This generally can't be done in a completely safe manner regardless of context, but it can be done.

The easiest way to do it is to do an interactive rebase ( potentially preserving merges ) and marking that you'd like to edit the commit messages, editing them and then force pushing the branch.

This will alter the hashes of all the commits starting from the first one you modify to the tip of the branch. If this branch is merged to master already, this is probably a bad idea unless you check with everyone else involved with the project.

Before you start this endeavor I strongly suggest you consider whether anyone else has consumed your branch yet, are there any merges you have to preserve, etc.

UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
  • Suppose I've merged to master, and I need the history change to propagate into master as well? – gzak Oct 06 '16 at 21:49
  • you'll have to do as i described, and then force push... but before you force push you are going to need to communicate very clearly to EVERYONE else who is on this repo what you are about to do, and make sure they are all aware of how they need to recover from the change. – UpAndAdam Oct 06 '16 at 21:52
  • also depending on where your git repo is hosted, you may or may not even be allowed to force push to master. – UpAndAdam Oct 06 '16 at 21:53
  • also take a look at 'git notes' – UpAndAdam Oct 07 '16 at 17:02