Exercises
Creating Snapshots
1- Initialize a new repository. Add two files in your working directory.
2- View the status of the working directory and the staging area.
3- Stage both files.
4- View the changes in the staging area.
5- Create a commit.
6- View the list of commits.
7- View the content of the last commit.
8- Update one of the files. View the changes in the working directory.
9- Stage the changes.
10- Unstage the file.
Solutions
1- Initialize a new repository. Add two text files in your working directory.
git init
echo hello > file1.txt
echo hello > file2.txt
2- View the status of the working directory and the staging area.
git status
git status -s
3- Stage both files.
git add .
4- View the changes in the staging area.
git diff --staged
5- Create a commit.
git commit -m “Initial commit.”
6- View the list of commits.
git log
7- View the content of the last commit.
git show HEAD
8- Update one of the files. View the changes in the working directory.
echo world >> file1.txt
git diff
9- Stage the changes.
git add file1.txt
10- Unstage the file.
git restore --staged file1.txt