When updating my git repository after changes, I normally issue the following commands:
git add .
git commit -m 'changes'
If I delete files during the session and run git add ., will this add these files to the repository again?
What’s the best approach for covering everything during a commit?
Best practice would probably be:
If you are only editing files for example:
That will add all changed files and open your configured editor so you can write the commit message. Under the commit message are the changes you are going to commit in diff format.
If you have more changes in your working copy, and only want to commit some of them use the staging area:
Again, using a verbose commit (show diff) and no message (so the editor opens) allows you easy control without missing anything.
If you close the editor without typing a commit message, the commit will be aborted. Quite often just skimming the diff – or even just the list of files to be commited – you’ll notice something missing or wrong and want to correct that.
using
git add .will add all files that you aren’t explicitly ignoring with your.gitignorefiles. That’s probably not the best way to commit by default, no doubt you’ve already committed files you didn’t really want in your repository that way.If you
git rma file, recreate the file, are not.gitignoreing the file and then rungit add .– you will just add the file back to the staged changes to be made in your next commit (which will then either be an edit to the file you originally deleted, or no action because the contents haven’t changed).