Does the command git commit takes a snapshot of my whole project or just of the staging area/index?
I already know that git commits are nodes of a graph, that every commit stores a pointer to the previous commit in the chain, that a branch is just a pointer to a commit and that HEAD is a pointer to the current branch.
However, I have been searching for an answer to this question on the Internet, but I seem to get different answers from different websites, and I can't get my head around this.
From Git pro book:
In order to begin tracking a new file, you use the command
git add.Now that your staging area is set up the way you want it, you can commit your changes. Remember that anything that is still unstaged — any files you have created or modified that you haven’t run git add on since you edited them — won’t go into this commit. They will stay as modified files on your disk.
From Git documentation
git-commit
Create a new commit containing the current contents of the index and the given log message describing the changes
As I can understand from those statements, it seems to me that git commit takes a snapshot of just the staging area.
However, looking for some answers in this sub I found:
This answer
In Git, all commits are immutable snapshots of your project (ignored files excluded) at a specific point in time. This means that each and every commit contains a unique representation of your entire project, not just the modified or added files (deltas), at the time of commit.
Everytime a new commit is created, a snapshot of your entire project is recorded and stored to the internal database following a DAG data structure.
And this answer
A "commit" in git is not a change (delta), but represents the entire state. But a commit contains more than just state: it also has a pointer to a parent commit (typically one, but can be any number), i.e. the previous commit in the repository's history.
After posting this question, I was able to find this answer too, that seems to give more details about the question:
You can have a lot of changes in a lot of files and only include in a commit a few of these changes. That does not mean that those other files are not part of the commit: technically all unchanged files are part of that commit, they are just not part of the commit diff.
From those answers, it seems to me that a commit is a snapshot of the whole state of the project at a given time.
Does somebody have a good, yet simple, explanation?