Is it a good idea to always write all files to git?
git commit -a
does not transfer all files. Instead, it only commits all files that are already under version control and have unstaged changes (in addition to the files already shipped).
-a, --all
Tell the command to automatically stage files that have been
modified and deleted, but new files you have not told Git about are
not affected.
This is different from git add -A
which adds all files and which other answers refer to. This will add everything without a trace and is not ignored (see gitignore ).
The use is git commit -a
not harmful per se. There are two problems that can arise:
-
Your commits can get large, making it difficult to find the cause of the regression (see git bisect ). To avoid this, you must study
git commit -p
. -
You can skip files that are not being tracked (this can only be avoided with the help of
git status
,git add
and your brain).
In terms of merges, git does merges based on individual changes to the file. This way, it doesn't matter how many files are in one commit. But making small commits usually results in fewer changes per file, making merging easier.
source to share
You don't want object files, executables (build output ie compiled binaries) and backup files (for example foo.html~
) to be git
.
So, you must have the file .gitignore
and you must install it as early as possible.
See also this
Once you're good enough .gitignore
using it git commit -a -m ....
, it's wise. I do this a lot.
source to share
It depends on what you have in your working directory.
If you only have source code and other version controlled files, this won't be a problem. But in many real-world projects, you accumulate various kinds of artifacts in your working directory that you don't want to be under version control (especially when they are binaries). Creating a .gitignore file that lists any files you don't want to use in source control can help.
Also, you sometimes work on multiple functions at the same time, but you were a sloppy git user and forgot to create a branch for each function. In this case, you probably want to capture both functions separately. This would mean that you create two commits, to which you add the necessary files manually.
source to share