Test with Regular Commits
In this step, we will practice creating more commits to build a history in our repository and see how git log
and git status
reflect these changes. This will simulate a more typical workflow where you make multiple changes and save them incrementally.
First, make sure you are in your project directory:
cd ~/project/my-time-machine
Now, let's add another line to our message.txt
file. We'll use the echo
command with >>
to append text to the existing file.
echo "Adding another line for testing." >> message.txt
Let's check the content of the file to confirm the change:
cat message.txt
You should see:
Hello, Future Me
Adding another line for testing.
Now, let's check the status of our repository:
git status
You should see output indicating that message.txt
has been modified:
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: message.txt
no changes added to commit (use "git add" and/or "git commit -a")
Git correctly identifies that the file has been changed since the last commit. Now, let's stage and commit this change.
git add message.txt
git commit -m "Add a second line to message.txt"
You should see output confirming the commit:
[master a1b2c3d] Add a second line to message.txt
1 file changed, 1 insertion(+)
We have now created a second commit. Let's view the commit history using git log
:
git log
You should now see two commit entries, with the newest commit at the top:
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9 (HEAD -> master)
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 10:00:00 2023 +0000
Add a second line to message.txt
commit f0e1d2c3b4a5968776543210fedcba9876543210
Author: Jane Doe <[email protected]>
Date: Mon Aug 7 09:55:00 2023 +0000
Send a message to the future
(Note: The commit hashes and dates will be different in your output).
This demonstrates the basic cycle of making changes, staging them with git add
, and saving them as a new commit with git commit
. Each commit represents a distinct point in your project's history, allowing you to track progress and revert to previous states if needed.
Press q
to exit the log.