Exercise - Creating Commits
Tips
git add <file/directory>Before a commit, changes must be registered withaddin 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 -aRegisters all changes to files already versioned in Git in the staging area, so you can save the separateaddcall.- The options
-aand-mcan 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/commits-erstellen/repo.
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/commits-erstellen/repo.
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/commits-erstellen/repo.
Create new-world and confirm it with a commit.
Step 4 - Commit - delete file
Start in directory git-uebungen/aufgaben/commits-erstellen/repo.
Delete hallo-welt and confirm this with a commit.
Step 5 - ⭐ Add - recursively add files
Start in directory git-uebungen/aufgaben/commits-erstellen/repo.
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/commits-erstellen/repo.
Rename the file hello-world to renamed-world and confirm this with a commit.
Step 7 - ⭐ Rename detection
Start in directory git-uebungen/aufgaben/commits-erstellen/repo.
Rename the file datei1 to datei2 with git mv. Make sure that the Rename Detection does not recognize this.
repo $ cd ..