1. Besides files and the commit message, what else is stored in a commit?
In addition to the files and commit message, the following information is also stored in a commit:
1- Author's name and email address:
When you first set up Git, you provide your username and email address. Git stores this information in the commit to identify who made the commit.2- Timestamp:
Git stores the date and time of when the commit was made, providing a record of when the change occurred.3- Parent commit ID:
As you saw in the commit graph, each new commit is connected to the previous commit (except for the initial commit). The previous commit becomes the parent of the new commit. This relationship is represented by storing the commit ID of the parent commit.
4- Other Information:
There is additional information stored in a commit, but the details mentioned above are the most important ones.
2. Why do I need to add files to the Index first? Can’t I directly add them to the Object Store?
You need to add files to the Index (also called the staging area) first because the Index acts as a "preparation zone" where you can decide exactly what to include in the next commit. It allows you to:
1- Select specific changes:
You can choose which files or parts of files to include, rather than committing everything at once.
2- Review your changes:
It gives you a chance to double-check what you're about to commit before finalizing it.
If you were to add files directly to the Object Store, you wouldn't have this control. Everything would go straight into a commit, making it harder to organize and manage your changes. The Index helps ensure you commit only the changes you actually want to include.
3. Why does Git store everything from the Index in a commit, even if only one file has changed since the last commit? Doesn’t that waste storage?
Git stores everything from the Index in a commit to keep track of the project’s complete state in a consistent and organized way. Even if only one file has changed, the Index represents the current state of all files to be included in the next commit.
4. Can I directly edit or modify files in the Index or Object Store?
You cannot directly edit or modify files in the Index or Object Store in Git. Here's why: The Index is not meant to be edited manually. It acts as a "pre-commit" zone where Git keeps track of the changes you intend to include in the next commit.
git add to update the
Index with those changes.