2

Is there any easier way to edit commit log ? (like the log that red-arrow pointing at)

If yes, How to do it in command line or in gittower ?

Thanks! enter image description here

newBike
  • 14,385
  • 29
  • 109
  • 192
  • Changing it will mess up the whole history (since that commit) and make it a pain for everyone who already has a clone of the repository, excluding you. – Jonas Schäfer Jan 24 '14 at 10:29
  • What if the log hasn't push to the server ? – newBike Jan 24 '14 at 10:31
  • 1
    possible duplicate of [How do I edit an incorrect commit message in Git?](http://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git) – krlmlr Jan 24 '14 at 10:37
  • @poc: In this case you can use the answers in the linked question. (Don't know if it covers git-tower, though.) – krlmlr Jan 24 '14 at 10:39
  • @krlmr The answer is in the linked question, but it's not obvious. Simply amending won't work for poc, he has to go through an interactive rebase. – Mike Monkiewicz Jan 24 '14 at 14:12

2 Answers2

2

As long as you haven't pushed to the server, you can use:

git rebase -i f88232a^

This will interactively rebase all commits starting at f88232a. The ^ is there to tell git to use the commit before f88232a as the root for the rebase operation. When you run this command, you're going to see something like:

pick f88232a Update
pick 57bfaca Change, redirect to index after finishing create
pick d23c917 Add missing column: result
...

Change the first pick to e or edit. Now you'll see

Stopped at f88232a... Update
You can amend the commit now, with

    git commit --amend

Once you are satisfied with your changes, run

    git rebase --continue

Now run

git commit --amend

Change your commit message & save, then run

git rebase --continue

Voila! Please note you are re-writing history all the way down to f88232a. Every commit from f88232a to the present will be replaced with a new commit with a new SHA. If you have any branches, this will get ugly quick, as those will stay based off the old commits. But it should do the trick.

Mike Monkiewicz
  • 4,481
  • 1
  • 22
  • 19
1

No, there isn't an easy way to do it (doesn't mean that there isn't a way, but it revolves changing every single commit after the offending commit).

Git was originally designed to make it very hard to change history. Enforce better commit description rules next time. (You can use hooks to perform basic checking).

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308