Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit a change with both "message" and "description" from the command line? [duplicate]

Tags:

git

github

I'm new to both git and GitHub. I managed to set up everything locally on my Mac, so that now I can push commits to GitHub via git (on the command line, not the Mac app).

When I push commits directly from the GitHub web interface (e.g. quickly fixing a typo), I have the chance to "comment" the commit, and GitHub gives me a commit title and a commit description. I find this very useful.

Still, when I git push from the local machine, git opens my default editor: so I write the commit comment, and then GitHub automatically divides it into title and "body". Is there a way to pretty comment commits from terminal too?

like image 275
whatyouhide Avatar asked Apr 20 '13 15:04

whatyouhide


People also ask

How do you write a multi line commit message?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.

How do I amend a commit with the same message?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.

What is the command to commit with the message?

To add a Git commit message to your commit, you will use the git commit command followed by the -m flag and then your message in quotes.


2 Answers

There is also another straight and more clear way

git commit -m "Title" -m "Description .........."; 
like image 172
zzlalani Avatar answered Oct 07 '22 12:10

zzlalani


Use the git commit command without any flags. The configured editor will open (Vim in this case):

enter image description here

To start typing press the INSERT key on your keyboard, then in insert mode create a better commit with description how do you want. For example:

enter image description here

Once you have written all that you need, to returns to git, first you should exit insert mode, for that press ESC. Now close the Vim editor with save changes by typing on the keyboard :wq (w - write, q - quit):

enter image description here

and press ENTER.

On GitHub this commit will looks like this:

enter image description here

As a commit editor you can use VS Code:

git config --global core.editor "code --wait" 

From VS Code docs website: VS Code as Git editor

Gif demonstration: enter image description here

like image 42
Mikhail Avatar answered Oct 07 '22 11:10

Mikhail