Is git commit -am redundant, if I do git add before?

前端 未结 5 937
忘了有多久
忘了有多久 2021-01-30 13:41

Is it redundant to run git add . and then git commit -am \"commit message\"?

Can I just run git add . and then git commit -m

5条回答
  •  北海茫月
    2021-01-30 14:05

    With Git before version 2.0, it's not redundant to run git commit -am if you deleted any tracked files. See further explanation of the options below.

    As long as you're in the root directory, and you want to add all new files, modifications and deletions, you want 3) below.

    1) Commit new files and modifications to previously-tracked files, but don't add deletions.

    With Git < 2.0:

    $ git add .
    $ git commit -m
    

    With Git >= 2.0:

    $ git add --ignore-removal .
    $ git commit -m
    

    2) Commit modifications and deletions to tracked files, but don't add new files.

    $ git commit -am
    

    3) Commit new files and all changed tracked files (both modifications and deletions). Either:

    With Git < 2.0:

    $ git add .
    $ git commit -am
    

    ...Or:

    $ git add -A
    $ git commit -m
    

    With Git >= 2.0:

    $ git add .
    $ git commit -m
    

提交回复
热议问题