Recording Changes
Last updated
Last updated
At this point, you should have a real Git repository on your local machine, and all of its files in front of you. Typically, you’ll want to start making changes and committing snapshots of those changes into your repository each time the project reaches a state you want to record.
Remember that each file in your working directory can be in one of two states:
Untracked state
Untracked files are not the files which git is simply not interested in
Tracked state
Tracked files are files that Git knows about
Tracked files are files that were in the last snapshot, as well as any newly staged files
Files which are in tracked state can be in any one of the condition below
Unmodified condition
Modified condition
Staged condition
When you first create a repository, all of your files will be untracked
because we have not instructed anything about it to Git!
Let us check the status of our working directory with the below command
We can see that the file is in untracked state
In order to begin tracking a new file, you use the command git add
. To begin tracking the hello.txt
file, you can run this:
If you run your status command again, you can see that your file is now tracked and staged to be committed:
You can tell that it’s staged
because it’s under the “Changes to be committed” heading!
Note: The git add
command takes a path name for either a file or a directory; if it’s a directory, the command adds all the files in that directory recursively.
Let us commit the changes to our local repository using the below command
It is recommended to use double quotes on Windows platform and single quote on Linux platform!
Now you’ve created your first commit! You can see that the commit has given you some output about itself:
which branch you committed to (master
),
what checksum the commit has (b1e291c
),
how many files were changed, and
statistics about lines added and removed in the commit.
Note: we will discuss branch later, checksum is a unique identifier issued by git database.
Every time you perform a commit, you’re recording a snapshot of your project that you can revert to or compare to later!
Let us check the status again to confirm if our commit went through by using the same command we used earlier:
The message we get from Git is self-explanatory.