Video in progress
Why does saving a change in Git take `git add` first and then `git commit`? Isn't one command enough?
The two steps let you choose exactly what goes into a commit. With add you gather the changes you want, and commit records them in history as one coherent step.
📖 Answer
During the day you mix several kinds of work: you fix a bug, add a log line on the side, and change one config to try something locally. If you cram everything into one commit, both review and revert get hard later.
git add src/main/java/.../PaymentService.java # just the fix
git commit -m "To'lov summasi manfiy bo'lsa xato qaytarish"
git add -p LoggingConfig.java # pick only some chunks of the file
git add -p is especially useful: it shows you each chunk of change in the file and asks "stage it?".
There is a shortcut too: git commit -am "..." automatically adds the files Git already tracks. But new files are not included, and people forget that.
Sign up to mark studied questions and save your progress.