git add . vs git commit -a

走远了吗. 提交于 2019-12-17 23:29:08

问题


What's the difference between:

  • git add .
  • git commit -a

Should I be doing both, or is that redundant?


回答1:


git commit -a means almost[*] the same thing as git add -u && git commit.

It's not the same as git add . as this would add untracked files that aren't being ignored, git add -u only stages changes (including deletions) to already tracked files.

[*] There's a subtle difference if you're not at the root directory of your repository. git add -u stages updates to files in the current directory and below, it's equivalent to git add -u . whereas git commit -a stages and commits changes to all tracked files.




回答2:


git commit -a automatically invokes git add on all files it knows about. You can use git add to select what files to commit. Consult the docs for more info: here




回答3:


By using the git commit -a switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index)



来源:https://stackoverflow.com/questions/3541647/git-add-vs-git-commit-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!