Masayuki Suzuki
Masayuki Suzuki

Reputation: 427

git add → git commit. Is this right?

Now I'm placticing Rails-tutorial practice3.1 and 3.2.

There is something I don't understand.

<solve first exercise>
    ★★★$ git commit -am "Eliminate repetition (solves exercise 3.1)"
<solve second exercise>
    $ git add -A
    $ git commit -m "Add a Contact page (solves exercise 3.2)"
    $ git push -u origin static-pages-exercises
    $ git checkout master

why did not do "git add" on ★★★?? I thought,


Actor(worktree)

↓↑ ★git add

index(staging area)

↓↓ ★git commit

local repository


So we can't git commit without git add, but we can.

Now I have just tested,

$ git commit -m "Add a Contact page (solves exercise 3.2)"

It's bad. (Changes not staged for commit)

   $ git commit -am "Add a Contact page (solves exercise 3.2)"

It's ok. (Add a Contact page (solves exercise 3.2)) ...why we can this???

Actually, I dont't know the meaning of option -a....

Please tell me

1)we can git commit without git add?

2)the meaning of git commit -a

thanks

Upvotes: 1

Views: 86

Answers (1)

sixty4bit
sixty4bit

Reputation: 7956

The -a flag allows you to add/stage the changed files in the same command as the commit. So using git commit -am "message" is the equivalent of git add -A followed by git commit -m "message".

https://git-scm.com/docs/git-add

https://git-scm.com/docs/git-commit

Upvotes: 1

Related Questions