Test Non-Merge Commits
In this step, we will create a regular commit (a non-merge commit) and then use git log
to see how it appears in our history compared to a merge commit (which we don't have yet, but will in future labs). This will help solidify your understanding of different commit types.
First, let's make a small change to our message.txt
file. We'll add another line.
Make sure you are in the ~/project/my-time-machine
directory:
cd ~/project/my-time-machine
Now, use the echo
command to append a new line to the file:
echo "Adding another line." >> message.txt
The >>
operator appends the text to the file instead of overwriting it.
Let's check the content of the file:
cat message.txt
You should see:
Hello, Future Me
Adding another line.
Now, let's check the status of our repository:
git status
You should see 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 sees the change we made. Now, let's stage and commit this change.
git add message.txt
git commit -m "Add a second line to message"
You should see output confirming the commit:
[master a1b2c3d] Add a second line to message
1 file changed, 1 insertion(+)
Now, let's look at our commit history again using git log --oneline
:
git log --oneline
You should see two commits:
e4f5g6h (HEAD -> master) Add a second line to message
a1b2c3d Send a message to the future
The latest commit (e4f5g6h
in this example, your hash will differ) is our new non-merge commit. It represents a single change made directly on the master
branch.
If we were to run git log --merges
again, it would still show no output because neither of these commits is a merge commit.
Understanding the difference between regular commits and merge commits is important for interpreting your project's history and collaborating effectively with others. Regular commits represent linear progress on a single line of development, while merge commits represent the integration of changes from different lines.