Exercise - Creating Commits
Tips
git add <file/directory>
Before a commit, changes must be registered withadd
in the staging area (also called the index).- The directory name
.
(which stands for current directory) can also be specified. The command is then applied to all files in the current directory and also subdirectories. git commit -m 'My two cents'
Creates a commit with all changes registered in the staging area.git commit -a
Registers all changes to files already versioned in Git in the staging area, so you can save the separateadd
call.- The options
-a
and-m
can also be combined:git commit -am "Comment"
git log --follow -- <file-name>
Shows the history of a file, even across renames.
Setup
In the repo
directory, a Git project is waiting to be edited.
Step 0 - START
$ cd repo
Step 1 - Commit - with Staging
Start in directory git-uebungen/aufgaben/<unknown>
.
Edit the file hallo-welt
, add it to the index with git add
(staging) and create a commit with these changes.
Step 2 - Commit - automatic staging
Start in directory git-uebungen/aufgaben/<unknown>
.
Edit the file hallo-welt
again and create another commit, but this time with -a
.
Step 3 - Commit - new file
Start in directory git-uebungen/aufgaben/<unknown>
.
Create new-world
and confirm it with a commit.
Step 4 - Commit - delete file
Start in directory git-uebungen/aufgaben/<unknown>
.
Delete hallo-welt
and confirm this with a commit.
Step 5 - ⭐ Add - recursively add files
Start in directory git-uebungen/aufgaben/<unknown>
.
Create a file superneu
and a directory sub
with a file auchneu
, add both with one add call and then create a commit.
Step 6 - ⭐ Commit - move/rename file
Start in directory git-uebungen/aufgaben/<unknown>
.
Rename the file hello-world
to renamed-world
and confirm this with a commit.
Step 7 - ⭐ Rename detection
Start in directory git-uebungen/aufgaben/<unknown>
.
Rename the file datei1
to datei2
with git mv
. Make sure that the Rename Detection does not recognize this.
repo $ cd ..