-7

Assuming that <filename> is being tracked by git, is git commit -m "message" <filename> possible without doing a git add <filename>?

Arun
  • 1
  • 1

2 Answers2

5

Yes. If you issue:

git commit -m "message" /file/to/save.c

save.c will be added and committed alone, provided that it is already tracked by Git.

You can find it mentioned in the Git commit manual page (point 3 of the first list).

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • Actually, I had to elaborate on the answer, because answering _"Yes."_ would have been a little embarassing :) – Stefano Sanfilippo Jan 25 '14 at 16:04
  • The first point says even changed files must be "added". Could you please explain? – Arun Jan 26 '14 at 16:52
  • 1
    If you want to commit files, either tracked or untracked by Git, then you have to `git add` them before `git commit -m "message"`. Writing `git commit -m "message" file1 file2` is a **shortcut** for `git add file1; git add file2; git commit -m "message"` _provided that Git is already tracking `file1` and `file2`_ (so no file will be added by mistake). That is to say, you are "implicitly" adding them. – Stefano Sanfilippo Jan 26 '14 at 17:06
  • Thanks Stefano! Finally understood it! :) – Arun Jan 28 '14 at 05:11
0

To avoid having to explicitly add each file you modify, you could use git commit -a -m "message": it will automatically add each tracked file and commit.

gturri
  • 13,807
  • 9
  • 40
  • 57