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

前端 未结 5 1005
忘了有多久
忘了有多久 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条回答
  •  Happy的楠姐
    2021-01-30 13:58

    I think some of the previous answers did not see the period after git add (your original question and some of the answers have since been edited to make the period more clear).

    git add . will add all files in the current directory (and any subdirectories) to the index (except those being ignored by .gitignore).

    The -a option to git commit will include all changes to files that are already being tracked by git, even if those changes have not been added to the index yet.

    Consequently, if all of the files are already being tracked by git, then the two approaches have the same effect. On the other hand, if new files have been created, then git add .; git commit will add them to the repository, while git commit -a will not.

    git add .; git commit -a is indeed redundant. All changes have already been added to the index, so the -a does nothing.

提交回复
热议问题