Exercise - Investigating the repository
This is about finding out what is in a repository.
Tips
git logshows all commits that are in the current branch.--onelinemakes the output more compact.
git show <some-commit>shows details about a commit- With
~you can address predecessors of a commit, e.g.HEAD~2is the predecessor of the predecessor ofHEAD. git branchandgit taglist existing branches and tags.- With
git switch <branch-name>you can switch to other branches. - With
git switch --detach <commit>you can switch to any version. - With
git restore -s <commit> -- <file-or-path>you can get contents of any version of files/paths into the workspace. It does not switch to the specified commit, but only fetches file contents into the workspace. The affected files are displayed asmodifiedand can be committed.
Setup
In the repo directory, a Git project is waiting to be examined.
Step 0 - START
$ cd repo
Step 1 - Show branches
Start in directory git-uebungen/aufgaben/repository-untersuchen/repo.
Show which branches exist. Now show the commit graph across all branches.
Step 2 - Switch branch
Start in directory git-uebungen/aufgaben/repository-untersuchen/repo.
Switch to the feature-a branch. Look at the content of the bar file in the foo directory. Switch back to main.
Step 3 - Show tags
Start in directory git-uebungen/aufgaben/repository-untersuchen/repo.
Show all tags.
Step 4 - ⭐ Investigate contents of past versions
Start in directory git-uebungen/aufgaben/repository-untersuchen/repo.
Show which files exist in the workspace. Show which files existed in the previous commit. Switch to the previous commit and examine what the workspace looks like then.
Then switch back to main.
Step 5 - ⭐ Restore old state of a single file.
Start in directory git-uebungen/aufgaben/repository-untersuchen/repo.
The file hallo-welt was edited after release1.0. The customer does not like it. Restore the old state with a new commit.
repo $ cd ..