Zulip Chat Archive

Stream: new members

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


view this post on Zulip 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?

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:12):

-a adds any changed files to the current commit

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:12):

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

view this post on Zulip 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"

view this post on Zulip Chris M (Jul 15 2020 at 05:13):

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

view this post on Zulip 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)

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:14):

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

view this post on Zulip 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

view this post on Zulip Chris M (Jul 15 2020 at 05:14):

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

view this post on Zulip Chris M (Jul 15 2020 at 05:15):

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

view this post on Zulip 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

view this post on Zulip Chris M (Jul 15 2020 at 05:16):

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

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:54):

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

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:55):

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

view this post on Zulip Scott Morrison (Jul 15 2020 at 05:55):

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

view this post on Zulip 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.

view this post on Zulip 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.

view this post on Zulip Johan Commelin (Jul 15 2020 at 06:08):

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

view this post on Zulip Johan Commelin (Jul 15 2020 at 06:08):

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

view this post on Zulip 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).

view this post on Zulip Johan Commelin (Jul 15 2020 at 06:11):

Ooh, ok. Neither did I

view this post on Zulip Kyle Miller (Jul 15 2020 at 06:11):

I just tried it, and it works as advertised.

view this post on Zulip 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?

view this post on Zulip Johan Commelin (Jul 16 2020 at 07:36):

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


Last updated: May 15 2021 at 00:39 UTC