0

not sure if you can do this but I am looking for the Syntax / Placement to add a new message when editing a commit via git commit --amend

I am aware that you can overwrite a message via git commit --amend -m '<over write message goes here>'.

In this case I have some commits that all fall into one batch - they are quick fixes and the aim is to reference there issue numbers on the message so this is shown in gitlabs.

Instead of having X commits per issue, I wanted to write a message like "#22 #24 #26 - batch update of small low level issues".

When I run: git commit --amend I am greeted with a VIM screen:

enter image description here

Where and how do I add to the current commit message on this page / is this possible?

I tried:

Keycommand: i (allows you to insert)

Then adding to the currently shown commit message at the top:

enter image description here

then

Keycommand: :wq (to write and save)

I get an issue: Aborting commit due to empty commit message.

So where do I need to add the commit message using this system?

thanks - W

1615903
  • 32,635
  • 12
  • 70
  • 99
Wally
  • 705
  • 1
  • 9
  • 24

1 Answers1

0

As it says -

Lines starting with '#' will be ignored

so put your commit message on that empty line, below "#24 ..." line.

kosist
  • 2,868
  • 2
  • 17
  • 30
  • Do I need to add a -m or any prefix? - also to mention the issue requires the use of # so does this need to be in quotes? – Wally Jan 10 '23 at 10:56
  • I guess you don't need to add prefix. – kosist Jan 10 '23 at 10:56
  • Cool so adding to where I suggested in the first place was correct - but because git ignores "#" it doesn't register the message - you need to add some charecter before the # so it knows its a message – Wally Jan 10 '23 at 10:59
  • Yes, you could simply try to remove beginning of that line, so no # is present there – kosist Jan 10 '23 at 11:23
  • But overall, amending commit messages - is not good practice. Because you are loosing history of small changes introduced in every commit. Consider rather squash commits while merging. I'm not sure which flow you use, but if you have, let's say, main -> then you create branch to do some changes -> you do multiple commits to new branch -> when it is ready and tested, you merge it back to main and do "squash commits". So in main branch, all your commits will be displayed as 1 commit only. And also, you can't ammend with pushed commits - only with local commits. – kosist Jan 10 '23 at 11:25
  • 1
    Ok great - looks like that can be done with the --squash command: found here https://stackoverflow.com/questions/5308816/how-can-i-merge-multiple-commits-onto-another-branch-as-a-single-squashed-commit. Good Idea thanks for the help Yeah not great practice but working locally and its for text changes so very low level stuff (adding full stops ect). Thanks again. – Wally Jan 10 '23 at 11:38