Home > Back-end >  Isn't git add an extra command?
Isn't git add an extra command?

Time:11-01

Isn't git add an extra command. Everything git add does can also be achieved by git commit if add command is removed. Just want to know others thought on it.

CodePudding user response:

They are not the same.

git add adds the modified files to the queue to be committed later so the files are not yet committed.

git commit on the other hand does commits the files that have been added and creates a new revision with a log (so in case you didn't add any files, git will not commit anything)

Note, that you can combine both commands with providing the -a flag at the end of the git commit like so: git commit -a

CodePudding user response:

You can, in many cases, use built-in features of git commit to add files to be committed at the same time you're committing, so that you don't need to use git add.

However, doing so deprives you of the opportunity to look at the staged and unstaged changes and verify you've collected the expected contents. For example, this past week, I wrote about four commits' worth of changes and then staged independent pieces of them with git add -p before committing, verifying at each step that I had included only the intended pieces. I could have done this with git commit -p, but I probably would have made a mistake.

For more advanced users, it tends to be a lot less common to use git commit with specific files and more common to stage changes with git add before committing.

  • Related