Make a Commit
In this section, we are going to
Check the status of your repo
Make a commit
Check status
If we inspect the commit history now, it will show nothing. To do that use git log
Let's create a file myfile.py
and place it in the repo (the same folder where .git
is located.
To check what Git oberves, use git status
There are two pieces of key information here:
No commits yet: this makes sense as this is an empty repo and we haven't made any commits. If you see some commit, it will be strange.
Git finds a file and lists it as "Untracked files". Although Git is tracking the contents in this folder, it needs us to tell it exactly what to put in a commit. So let's track this file. To do that, use
git add
.
If you have multiple files, then
git add file1 file2 folder1 ...
If you just want to add all changes
git add .
Then do git status
again.
Commit
Now it's ready to be commited. To commit use git commit -m <message>
. You might be prompted to enter your user name and password if it's your first commit. Just follow the instructions to set it up using git config --global
.
This shows a successful commit. Git also identifies that one file is added and there are two lines of change in that file (2 insertions). You can aslo see the first-8-digit excerpt of the hash for this commit (c96c526). Your hash might be different from here, since the first commit hash is random.
If we inspect the commit history now, we can see the whole hash as well as the commit message.
What is the direct command prior to
git commit
. Why do you think it's needed?
Do it yourself
Make two more commits. Each commit adds one line to myfile.py
. One prints the mean and the other prints the standard deviation of arr
.
By the end, you will get something like this (note the long string following the word "commit", i.e. a HASH, will be different from here).
Last updated