This kata will examine the staging area of git.
In git we are working with three different areas:
- The working directory where you are making your changes
- The staging area where all changes you have added through
git add
will stay - The repository where every commit ends up, making your history. To put your staged changes in here you issue the
git commit
command.
A file can have changes both in the working directory and staging area at the same time. These changes do not have to be the same.
We will also work with git restore
to restore the staged changes of a file, and git checkout
to return a file to a previous state.
- Run
source setup.sh
(or.\setup.ps1
in PowerShell)
You live in your own repository. There is a file called file.txt
.
- What's the content of
file.txt
? - Overwrite the content in
file.txt
:echo 2 > file.txt
to change the state of your file in the working directory (orsc file.txt '2'
in PowerShell) - What does
git diff
tell you? - What does
git diff --staged
tell you? why is this blank? - Run
git add file.txt
to stage your changes from the working directory. - What does
git diff
tell you? - What does
git diff --staged
tell you? - Overwrite the content in
file.txt
:echo 3 > file.txt
to change the state of your file in the working directory (orsc file.txt '3'
in PowerShell). - What does
git diff
tell you? - What does
git diff --staged
tell you? - Explain what is happening
- Run
git status
and observe thatfile.txt
are present twice in the output. - Run
git restore --staged file.txt
to unstage the change - What does
git status
tell you now? - Stage the change and make a commit
- What does the log look like?
- Overwrite the content in
file.txt
:echo 4 > file.txt
(orsc file.txt '4'
in PowerShell) - What is the content of
file.txt
? - What does
git status
tell us? - Run
git restore file.txt
- What is the content of
file.txt
? - What does
git status
tell us?
git add
git commit
git commit -m "My lazy short commit message"
git log
git log -n 5
git log --oneline
git log --oneline --graph
git restore --staged
You can set up aliases as such:
git config --global alias.lol 'log --oneline --graph --all'
This might be useful to you.