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 addwill stay - The repository where every commit ends up, making your history. To put your staged changes in here you issue the
git commitcommand.
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 reset to reset the staged changes of a file, and git checkout to return a file to a previous state.
- Run
. setup.sh(or.\setup.ps1in 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.txtto change the state of your file in the working directory (orsc file.txt '2'in PowerShell) - What does
git difftell you? - What does
git diff --stagedtell you? why is this blank? - Run
git add file.txtto stage your changes from the working directory. - What does
git difftell you? - What does
git diff --stagedtell you? - Overwrite the content in
file.txt:echo 3 > file.txtto change the state of your file in the working directory (orsc file.txt '3'in PowerShell). - What does
git difftell you? - What does
git diff --stagedtell you? - Explain what is happening
- Run
git statusand observe thatfile.txtare present twice in the output. - Run
git reset HEAD file.txtto unstage the change - What does
git statustell 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 statustell us? - Run
git checkout file.txt - What is the content of
file.txt? - What does
git statustell us?
git addgit commitgit commit -m "My lazy short commit message"git resetgit checkoutgit loggit log -n 5git log --onelinegit log --oneline --graphgit reset HEADgit checkout
You can set up aliases as such:
git config --global alias.lol 'log --oneline --graph --all'
This might be useful to you.