Zulip Chat Archive

Stream: new members

Topic: What does `git commit -am` do?


Chris M (Jul 15 2020 at 05:11):

I've been trying to understand git better so I know what I'm doing when contributing to mathlib. One particular thing I don't get is what git commit -am does. How is it different from just git commit?

Scott Morrison (Jul 15 2020 at 05:12):

-a adds any changed files to the current commit

Scott Morrison (Jul 15 2020 at 05:12):

(so you don't need to separately type git add file1 file2 or git add . beforehand)

Scott Morrison (Jul 15 2020 at 05:13):

-m says that you're going to specify a commit message as a quoted string immediately afterwards: git commit -am "amazing new maths"

Chris M (Jul 15 2020 at 05:13):

is it generally the case that -abc is equivalent to -a -b -c in terminals?

Scott Morrison (Jul 15 2020 at 05:13):

rather than have git open an editor for you to provide your commit message (which, if you're unlucky or unprepared, might be vi)

Scott Morrison (Jul 15 2020 at 05:14):

It's very often the case for unix command line tools, although not completely universal.

Jalex Stark (Jul 15 2020 at 05:14):

there's no typechecker for new unix command line tools, but the single letter flag thing is a strong convention

Chris M (Jul 15 2020 at 05:14):

Does it depend on the terminal language? or on the service?

Chris M (Jul 15 2020 at 05:15):

So it is a choice by Lean that -am means -a -m?

Jalex Stark (Jul 15 2020 at 05:15):

i wouldn't call it a choice, it's just the conventional way to write command line tools

Chris M (Jul 15 2020 at 05:16):

alright. (I meant "defined in the Lean command line interpreter, not in the terminal itself").

Scott Morrison (Jul 15 2020 at 05:54):

@Chris M , this has nothing to do with Lean.

Scott Morrison (Jul 15 2020 at 05:55):

We're just talking about all unix command line tools, git in particular.

Scott Morrison (Jul 15 2020 at 05:55):

There's no "Lean command line interpreter" at all.

Kyle Miller (Jul 15 2020 at 06:05):

Scott Morrison said:

-a adds any changed files to the current commit

Just for clarification, "changed files" here means files that are already in the git repository that have been changed. If you create a new file, you'll need to git add the file before you git commit or git commit -am "even more amazing new maths".

If you want a multi-paragraph commit message without using a text editor, you can do git commit -am "short description" -m "longer description" -m "maybe another detail". Each additional message introduces another paragraph.

Johan Commelin (Jul 15 2020 at 06:07):

Chris M said:

is it generally the case that -abc is equivalent to -a -b -c in terminals?

"generally" as in "a lot of programs support this". But there are exceptions.

Johan Commelin (Jul 15 2020 at 06:08):

Oops, I see that 10 other people already made that remark :face_palm:

Johan Commelin (Jul 15 2020 at 06:08):

@Kyle Miller I think every new -m introduces a new line, right?

Kyle Miller (Jul 15 2020 at 06:09):

From the manual,

       -m <msg>, --message=<msg>
           Use the given <msg> as the commit message. If multiple -m options
           are given, their values are concatenated as separate paragraphs.

(though, admittedly, I've never tried it myself).

Johan Commelin (Jul 15 2020 at 06:11):

Ooh, ok. Neither did I

Kyle Miller (Jul 15 2020 at 06:11):

I just tried it, and it works as advertised.

Chris M (Jul 16 2020 at 07:34):

Scott Morrison said:

There's no "Lean command line interpreter" at all.

isn't leanproject a command line tool with a command line interpreter?

Johan Commelin (Jul 16 2020 at 07:36):

Yes... but leanproject is a python script that does not call lean


Last updated: Dec 20 2023 at 11:08 UTC