Test Non-Amended Commits
In this step, we will create a new commit without using the --amend
flag and observe how it appears in both git log
and git reflog
. This will help solidify your understanding of how these commands track history differently.
First, let's add some more content to our message.txt
file. We'll append a new line:
echo "Hello again, Future Me!" >> message.txt
The >>
operator appends the text to the existing file, rather than overwriting it.
Now, let's check the status to see the changes:
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")
Next, we need to stage the changes:
git add message.txt
And now, let's create a new commit without amending the previous one:
git commit -m "Add another message"
You should see output confirming the new commit:
[master 1a2b3c4] Add another message
1 file changed, 1 insertion(+)
Now, let's check the git log
again:
git log --oneline
This time, you should see two commits:
1a2b3c4 (HEAD -> master) Add another message
a1b2c3d Send a message to the future
Both commits are visible in the git log
because the second commit was added on top of the first one, extending the branch's history.
Finally, let's check the git reflog
:
git reflog
You should see output similar to this:
1a2b3c4 (HEAD -> master) HEAD@{0}: commit: Add another message
1a2b3c4 (HEAD -> master) HEAD@{1}: commit (amend): Send a message to the future
e4f5g6h HEAD@{2}: commit (initial): Send a message to the future
Notice that git reflog
shows all the actions: the initial commit, the amended initial commit, and the new commit we just created. Each action that moved HEAD
is recorded.
This step demonstrates that when you create a new commit without --amend
, both git log
and git reflog
will show the new commit, but git reflog
will still retain the history of the amended commit, which git log
does not.