1

I transferred my gist and all its revisions into a git repo thanks to this great Github import feature.

But now all the commit messages are empty:

No commit message
UserA committed on GitHub 27 days ago

How to change the commit message of all these 9 or 10 commits, one month later?

(Is it possible directly in Github's website?)

Community
  • 1
  • 1
Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

1

Well you can use git rebase -i HEAD^8 to interactivly change the messages. This will open an editor and you can change the commit messages and you change the word pick to reword and can now reword every single commit message. Be aware that this action rewrites your whole history which means you have to do git push --force to update the remote repository.

By doing git push --force you will update the remote history as well, which means that contributer have to re-pull or even re-clone the repository to integrate the new history which can lead to horrible merges or even loss of changes.

ckruczek
  • 2,361
  • 2
  • 20
  • 23
  • 1
    Complementary note: if you don't understand what `git push --force` does, you should at least know that this is a potentially dangerous operation, don't run it blindly. – Matthieu Moy Jan 11 '17 at 10:44
  • Thanks for your comment, I will update the answer and add your information respectivly. – ckruczek Jan 11 '17 at 10:45
  • How to do this for all commits? should I do `git rebase -i ` ? – Basj Jan 11 '17 at 11:45
  • Something else: in the editor (is it a vim?) what should I write to rename to "First commit"? I tried `rFirst commit` (r for reword) then `ESC` then `:wq`, but then I get `Unknown command: rFirst commit`. – Basj Jan 11 '17 at 11:49
  • You can also start a new branch at the current tip to hold your old version, and do the interactive rebase to update the messages, and then do a rename to swap over the branches, though that maybe more phaff than it's worth. – Philip Oakley Jan 11 '17 at 11:56
  • @Basj you change the words 'pick' to 'reword' in the editor. You save the file, and then git starts to open every commit and let you change the commit message. – ckruczek Jan 11 '17 at 12:22
  • @ckruczek: with `nano` now as my default editor, this is what I get when doing `git rebase -i` : http://gget.it/8huetr9x/1.jpg. I tried to replace `noop` by `r` then save and quit, error (`fatal: Needed a single revision Invalid commit name:`). Idem by replacing `noop` by `reword` and save and quit. What is wrong? – Basj Jan 11 '17 at 12:36
  • Ok I might missed something in my answer. You have to define how many commits you want to update. See the updated answer – ckruczek Jan 11 '17 at 12:40
  • The answer is right, you have to use `squash` which is the `git rebase -i HEAD~` but keep in mind that even if you choose 10 commits back you can have more commits since merge commits will be shown as well with all their commits. if you had 5 comits in merge you will see them as well. – CodeWizard Jan 11 '17 at 13:02
  • @ckruczek I get `fatal: Needed a single revision invalid upstream HEAD~9`. The same with `HEAD^9`. Any idea? – Basj Jan 11 '17 at 15:09
  • Yes 9 was one to much I guess. So try 8 instead. I'll update my answer accordingly – ckruczek Jan 11 '17 at 15:16
  • @ckruczek I tried with a new fresh and clean clone (can you try the same?) : `git clone https://github.com/josephernest/wavfile.py.git` `cd wavfile.py` `git rebase -i HEAD^8`. Then `fatal: Needed a single revision // invalid upstream HEAD^8`. Thanks in advance! – Basj Jan 11 '17 at 16:01