Reputation: 7508
I am learning Git commands.
My understanding of git add and git commit is as follows: git add 'file name' takes snapshot of the project(entire working directory) and stage it. git commit saves the staged snapshot to the repository.
I also understand that git differs from SVN etc in the fundamental way of saving the files. While SVN saves incremental changes in individual files, git saves snapshot of the entire working directory. If a file has not changed, git snapshot would contain a reference that file in the previous snapshot.
I have a question here. If git add takes snapshot of entire working directory why do we need to provide individual file name in the command? Git would anyway take snapshot of entire project.
Upvotes: 3
Views: 12555
Reputation: 882146
Because you may not want to add every single file that's been added or changed.
For example, let's say you've modified your xyzzy.c
file but you also downloaded a very nice picture, taylor_swift.jpg
, to the current directory (and haven't yet had a chance to move it elsewhere).
You don't want the latter file to find its way into the repo, so you simply do:
git add xyzzy.c
abd that adds only the file you want added.
In any case, if you want every file in the current directory, you can simply do:
git add .
I tend to think of it as the three areas.
First, your working area where you have a specific "snapshot" checked out, with whatever changes you've made.
Then the staging area that holds files for the next commit.
And, finally, the git-proper area that holds all committed changes.
If you think in those terms, add
then copies individual things from working to staging, and commit
copies everything from staging to git-proper.
Upvotes: 3
Reputation: 3616
Your comprehension about snapshot in git is wrong. As shown in document of git website, [Snapshots, Not Differences], the snapshot of your project is an aggregation of snapshot for each files you added in your repository. This is the reason you need specify filename in git add
command.
After you tell git which file should be managed by git add <filename>
, you can use git add -u
to stage your modification, in this case, filename is not necessary.
Upvotes: 1
Reputation: 7142
Checkout the git documentation about git add
simply you can use .
You can use git add .
this will take entire directory / new files / modified files - ready to commit.
Upvotes: 0