Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git, adding changes to commit, difference between add and commit flags

Tags:

git

Is -a in git commit -a equivalent to git add . -A?

Assuming i have the following aliases:

 12 alias gita='git add . -A'
 13 alias gits='clear; git status'
 14 alias gitlog='git log --pretty=oneline --abbrev-commit'
 15 alias commit='git commit -a '

 16 alias check='gita;commit'  <--------------------------

When i say check, is there any redundancy happening when i both add -A and commit -a

like image 626
James Raitsev Avatar asked Jan 14 '12 21:01

James Raitsev


3 Answers

git add -A is NOT equivalent to the -a flag in git commit. git add -u is. It adds changes to tracked files (including rms). git add -A also brings in untracked files.

Since git add -A is superset of git add -u, that is enough and you need not specify the -a in commit as well.

Also, if the path is not given, it is assumed to be ., so the . is superfluous as well.

Starting git 2.0 (mid 2013), you will need to add the path, or git add -A would operate on the full working tree.

See "Difference of “git add -A” and “git add .”".

like image 153
manojlds Avatar answered Nov 20 '22 16:11

manojlds


Sort of. git add -A will match against the working tree and the index, adding new files, marking modified files and removing deleted files. git commit -a will stage only files that have been added or modified, but new files will not be added unless already specified in a prior git add

like image 22
jmkeyes Avatar answered Nov 20 '22 18:11

jmkeyes


Is -a in git commit -a equivalent to git add . -A?

No it is not. git add . -u is.

When i say check, is there any redundancy happening when i both add -A and commit -a

No git commit -a will simply add the remaining files by itself. In this case: none.

like image 39
TimWolla Avatar answered Nov 20 '22 16:11

TimWolla