Test with Different Repository States
In this step, we will create some changes in our repository to see how git status --porcelain
reports them. This will help you understand the different codes used in the porcelain output.
First, make sure you are in the correct directory:
cd ~/project/my-time-machine
Now, let's create a new, untracked file. We'll call it notes.txt
:
echo "Some random notes" > notes.txt
Run git status --porcelain
again:
git status --porcelain
You should now see output similar to this:
?? notes.txt
The ??
indicates that notes.txt
is an untracked file. Git sees the file but isn't currently managing its versions.
Next, let's modify the message.txt
file that we committed earlier. We'll add another line to it:
echo "Hello again, Future Me" >> message.txt
The >>
operator appends the text to the existing file, rather than overwriting it.
Now, run git status --porcelain
one more time:
git status --porcelain
You should see output similar to this:
M message.txt
?? notes.txt
The M
indicates that message.txt
has been modified. The space before the M
means the change is in the working directory but has not been staged yet. The ??
for notes.txt
remains because it's still untracked.
Finally, let's stage the modified message.txt
file using git add
:
git add message.txt
And run git status --porcelain
one last time:
git status --porcelain
The output should now look like this:
M message.txt
?? notes.txt
The M
is now in the first column, indicating that message.txt
has been staged for commit. The space in the second column means there are no further modifications in the working directory since it was staged. notes.txt
is still untracked.
Understanding these codes (??
for untracked, M
in the second column for modified but not staged, M
in the first column for staged modifications) is key to quickly interpreting the git status --porcelain
output.