Check git status for Applied Changes
In this step, we will explore how Git's stash
command interacts with the working directory and how to check the status of your repository after applying a stash.
First, let's make sure we are in our project directory. Open your terminal and navigate to the my-time-machine
directory:
cd ~/project/my-time-machine
Now, let's create a new file and add some content to simulate having uncommitted changes:
echo "This is a new feature." > feature.txt
echo "Adding some more content." >> message.txt
We have now created a new file feature.txt
and modified the existing message.txt
. Let's see how Git views these changes using git status
:
git status
You should see output indicating that feature.txt
is untracked and 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
Untracked files:
(use "git add <file>..." to include in what will be committed)
feature.txt
no changes added to commit (use "git add" and/or "git commit -a")
Now, let's stash these changes. Stashing is like putting your current work aside temporarily so you can switch to something else without committing incomplete changes.
git stash save "Work in progress"
You should see output confirming the stash was saved:
Saved working tree and index state On master: Work in progress
Your working directory should now be clean, as if you hadn't made those changes. You can verify this with git status
:
git status
The output should show a clean working directory:
On branch master
nothing to commit, working tree clean
Now, let's apply the stash we just created. Applying a stash brings the stashed changes back into your working directory.
git stash apply
You should see output indicating the changes were applied:
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
Untracked files:
(use "git add <file>..." to include in what will be committed)
feature.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9)
Finally, let's check the git status
again to see the state of our working directory after applying the stash.
git status
The output should show that the changes from the stash are now back in your working directory, appearing as modified and untracked files, just like before we stashed them. This confirms that git stash apply
brings the changes back without automatically staging or committing them.