chore: initial training material setup
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
# ✅ Lösung – Aufgabe 02: Erste Schritte
|
||||
|
||||
> Schau dir diese Lösung erst an, nachdem du die Aufgabe selbst versucht hast!
|
||||
|
||||
---
|
||||
|
||||
## Schritt-für-Schritt-Lösung
|
||||
|
||||
### 1. Ordner anlegen und initialisieren
|
||||
|
||||
```bash
|
||||
mkdir meine-notizen
|
||||
cd meine-notizen
|
||||
git init
|
||||
```
|
||||
|
||||
```text
|
||||
Initialized empty Git repository in /pfad/zu/meine-notizen/.git/
|
||||
```
|
||||
|
||||
### 2. Datei anlegen – Commit 1
|
||||
|
||||
Erstelle `notizen.md` und füge die erste Zeile ein:
|
||||
|
||||
```bash
|
||||
echo "Git ist ein Versionskontrollsystem." > notizen.md
|
||||
git add notizen.md
|
||||
git commit -m "docs: Erste Notiz – Was ist Git?"
|
||||
```
|
||||
|
||||
```text
|
||||
[main (root-commit) a1b2c3d] docs: Erste Notiz – Was ist Git?
|
||||
1 file changed, 1 insertion(+)
|
||||
create mode 100644 notizen.md
|
||||
```
|
||||
|
||||
### 3. Zweite Zeile – Commit 2
|
||||
|
||||
Öffne `notizen.md` und füge Zeile 2 hinzu. Dann:
|
||||
|
||||
```bash
|
||||
git add notizen.md
|
||||
git commit -m "docs: Zweite Notiz – Was sind Commits?"
|
||||
```
|
||||
|
||||
```text
|
||||
[main e4f5g6h] docs: Zweite Notiz – Was sind Commits?
|
||||
1 file changed, 1 insertion(+)
|
||||
```
|
||||
|
||||
### 4. Dritte Zeile – Commit 3
|
||||
|
||||
Öffne `notizen.md` und füge Zeile 3 hinzu. Dann:
|
||||
|
||||
```bash
|
||||
git add notizen.md
|
||||
git commit -m "docs: Dritte Notiz – Was ist die Staging Area?"
|
||||
```
|
||||
|
||||
```text
|
||||
[main i7j8k9l] docs: Dritte Notiz – Was ist die Staging Area?
|
||||
1 file changed, 1 insertion(+)
|
||||
```
|
||||
|
||||
### 5. Erwartete Log-Ausgabe
|
||||
|
||||
```bash
|
||||
git log --oneline
|
||||
```
|
||||
|
||||
```text
|
||||
i7j8k9l (HEAD -> main) docs: Dritte Notiz – Was ist die Staging Area?
|
||||
e4f5g6h docs: Zweite Notiz – Was sind Commits?
|
||||
a1b2c3d docs: Erste Notiz – Was ist Git?
|
||||
```
|
||||
|
||||
### 6. Abschlussprüfung
|
||||
|
||||
```bash
|
||||
git status
|
||||
```
|
||||
|
||||
```text
|
||||
On branch main
|
||||
nothing to commit, working tree clean
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Fertiger Inhalt von notizen.md
|
||||
|
||||
```text
|
||||
Git ist ein Versionskontrollsystem.
|
||||
Commits sind Snapshots meines Projekts.
|
||||
Die Staging Area bereitet Commits vor.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*Zurück zur [Aufgabe](../02-erste-schritte/aufgabe.md)*
|
||||
@@ -0,0 +1,125 @@
|
||||
# ✅ Lösung – Aufgabe 03: Branches
|
||||
|
||||
> Schau dir diese Lösung erst an, nachdem du die Aufgabe selbst versucht hast!
|
||||
|
||||
---
|
||||
|
||||
## Schritt-für-Schritt-Lösung
|
||||
|
||||
### 1. Ausgangssituation herstellen
|
||||
|
||||
```bash
|
||||
mkdir branch-uebung
|
||||
cd branch-uebung
|
||||
git init
|
||||
echo "# Branch-Übung" > README.md
|
||||
git add README.md
|
||||
git commit -m "chore: Projekt angelegt"
|
||||
```
|
||||
|
||||
### 2. Feature-Branch anlegen
|
||||
|
||||
```bash
|
||||
git switch -c feature/begruessung
|
||||
```
|
||||
|
||||
```text
|
||||
Switched to a new branch 'feature/begruessung'
|
||||
```
|
||||
|
||||
### 3. Datei erstellen und committen
|
||||
|
||||
```bash
|
||||
echo "Hallo, Welt!" > hallo.txt
|
||||
echo "Willkommen in meinem ersten Git-Projekt." >> hallo.txt
|
||||
git add hallo.txt
|
||||
git commit -m "feat: Begrüßungsdatei hinzugefügt"
|
||||
```
|
||||
|
||||
```text
|
||||
[feature/begruessung c3d4e56] feat: Begrüßungsdatei hinzugefügt
|
||||
1 file changed, 2 insertions(+)
|
||||
create mode 100644 hallo.txt
|
||||
```
|
||||
|
||||
### 4. Zurück zu main
|
||||
|
||||
```bash
|
||||
git switch main
|
||||
```
|
||||
|
||||
```text
|
||||
Switched to branch 'main'
|
||||
```
|
||||
|
||||
Prüfe, ob `hallo.txt` da ist:
|
||||
|
||||
```bash
|
||||
ls
|
||||
```
|
||||
|
||||
```text
|
||||
README.md
|
||||
```
|
||||
|
||||
`hallo.txt` fehlt – korrekt! Auf `main` existiert sie noch nicht.
|
||||
|
||||
### 5. Commit-Übersicht beider Branches
|
||||
|
||||
```bash
|
||||
git log --all --oneline --graph
|
||||
```
|
||||
|
||||
```text
|
||||
* c3d4e56 (feature/begruessung) feat: Begrüßungsdatei hinzugefügt
|
||||
* a1b2c3d (HEAD -> main) chore: Projekt angelegt
|
||||
```
|
||||
|
||||
### 6. Merge
|
||||
|
||||
```bash
|
||||
git merge feature/begruessung
|
||||
```
|
||||
|
||||
```text
|
||||
Updating a1b2c3d..c3d4e56
|
||||
Fast-forward
|
||||
hallo.txt | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
create mode 100644 hallo.txt
|
||||
```
|
||||
|
||||
`hallo.txt` ist jetzt auf `main` vorhanden.
|
||||
|
||||
### 7. Branch aufräumen
|
||||
|
||||
```bash
|
||||
git branch -d feature/begruessung
|
||||
```
|
||||
|
||||
```text
|
||||
Deleted branch feature/begruessung (was c3d4e56).
|
||||
```
|
||||
|
||||
### Abschlusszustand
|
||||
|
||||
```bash
|
||||
git log --oneline
|
||||
```
|
||||
|
||||
```text
|
||||
c3d4e56 (HEAD -> main) feat: Begrüßungsdatei hinzugefügt
|
||||
a1b2c3d chore: Projekt angelegt
|
||||
```
|
||||
|
||||
```bash
|
||||
git branch
|
||||
```
|
||||
|
||||
```text
|
||||
* main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*Zurück zur [Aufgabe](../03-branches/aufgabe.md)*
|
||||
@@ -0,0 +1,158 @@
|
||||
# ✅ Lösung – Aufgabe 04: Merge & Konflikte
|
||||
|
||||
> Schau dir diese Lösung erst an, nachdem du die Aufgabe selbst versucht hast!
|
||||
|
||||
---
|
||||
|
||||
## Schritt-für-Schritt-Lösung
|
||||
|
||||
### 1. Ausgangssituation
|
||||
|
||||
```bash
|
||||
mkdir konflikt-uebung
|
||||
cd konflikt-uebung
|
||||
git init
|
||||
cp ../04-merge-und-konflikte/konflikt-vorlage.txt .
|
||||
git add konflikt-vorlage.txt
|
||||
git commit -m "chore: Vorlage hinzugefügt"
|
||||
```
|
||||
|
||||
### 2. Ersten Feature-Branch erstellen und ändern
|
||||
|
||||
```bash
|
||||
git switch -c feature/version-a
|
||||
```
|
||||
|
||||
Öffne `konflikt-vorlage.txt` und ändere Zeile 3 zu:
|
||||
|
||||
```text
|
||||
Zeile 3: Dies ist Version A – geändert von Branch feature/version-a.
|
||||
```
|
||||
|
||||
```bash
|
||||
git add konflikt-vorlage.txt
|
||||
git commit -m "feat: Version A in Zeile 3 eingetragen"
|
||||
```
|
||||
|
||||
### 3. Fast-Forward-Merge
|
||||
|
||||
```bash
|
||||
git switch main
|
||||
git merge feature/version-a
|
||||
```
|
||||
|
||||
```text
|
||||
Updating a1b2c3d..b2c3d4e
|
||||
Fast-forward
|
||||
konflikt-vorlage.txt | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
```
|
||||
|
||||
Kein Merge-Commit! `main` wurde einfach vorgespult.
|
||||
|
||||
### 4. Zweiten Feature-Branch erstellen
|
||||
|
||||
```bash
|
||||
git switch -c feature/version-b
|
||||
```
|
||||
|
||||
Öffne `konflikt-vorlage.txt` und ändere Zeile 3 zu:
|
||||
|
||||
```text
|
||||
Zeile 3: Dies ist Version B – geändert von Branch feature/version-b.
|
||||
```
|
||||
|
||||
```bash
|
||||
git add konflikt-vorlage.txt
|
||||
git commit -m "feat: Version B in Zeile 3 eingetragen"
|
||||
```
|
||||
|
||||
### 5. main auch ändern (Konflikt vorbereiten)
|
||||
|
||||
```bash
|
||||
git switch main
|
||||
```
|
||||
|
||||
Öffne `konflikt-vorlage.txt` und ändere Zeile 3 zu:
|
||||
|
||||
```text
|
||||
Zeile 3: Dies ist die main-Version – direkt auf main geändert.
|
||||
```
|
||||
|
||||
```bash
|
||||
git add konflikt-vorlage.txt
|
||||
git commit -m "fix: Zeile 3 auf main angepasst"
|
||||
```
|
||||
|
||||
### 6. Konflikt provozieren
|
||||
|
||||
```bash
|
||||
git merge feature/version-b
|
||||
```
|
||||
|
||||
```text
|
||||
Auto-merging konflikt-vorlage.txt
|
||||
CONFLICT (content): Merge conflict in konflikt-vorlage.txt
|
||||
Automatic merge failed; fix conflicts and then commit the result.
|
||||
```
|
||||
|
||||
### 7. Konflikt ansehen
|
||||
|
||||
Öffne `konflikt-vorlage.txt`. Du siehst:
|
||||
|
||||
```text
|
||||
Zeile 1: Diese Zeile wird nicht verändert.
|
||||
Zeile 2: Diese Zeile wird auch nicht verändert.
|
||||
<<<<<<< HEAD
|
||||
Zeile 3: Dies ist die main-Version – direkt auf main geändert.
|
||||
=======
|
||||
Zeile 3: Dies ist Version B – geändert von Branch feature/version-b.
|
||||
>>>>>>> feature/version-b
|
||||
Zeile 4: Diese Zeile bleibt wieder gleich.
|
||||
Zeile 5: Ende der Vorlage.
|
||||
```
|
||||
|
||||
### 8. Konflikt auflösen
|
||||
|
||||
Entscheide dich für eine Lösung – zum Beispiel eine Kombination:
|
||||
|
||||
```text
|
||||
Zeile 1: Diese Zeile wird nicht verändert.
|
||||
Zeile 2: Diese Zeile wird auch nicht verändert.
|
||||
Zeile 3: Finale Version – kombiniert aus main und feature/version-b.
|
||||
Zeile 4: Diese Zeile bleibt wieder gleich.
|
||||
Zeile 5: Ende der Vorlage.
|
||||
```
|
||||
|
||||
Alle Konfliktmarker entfernen, dann:
|
||||
|
||||
```bash
|
||||
git add konflikt-vorlage.txt
|
||||
git commit -m "fix: Merge-Konflikt in konflikt-vorlage.txt aufgelöst"
|
||||
```
|
||||
|
||||
```text
|
||||
[main f6g7h8i] fix: Merge-Konflikt in konflikt-vorlage.txt aufgelöst
|
||||
```
|
||||
|
||||
### 9. Abschlusszustand
|
||||
|
||||
```bash
|
||||
git log --oneline --graph
|
||||
```
|
||||
|
||||
```text
|
||||
* f6g7h8i (HEAD -> main) fix: Merge-Konflikt aufgelöst
|
||||
|\
|
||||
| * e5f6g7h (feature/version-b) feat: Version B in Zeile 3 eingetragen
|
||||
* | d4e5f6g fix: Zeile 3 auf main angepasst
|
||||
|/
|
||||
* b2c3d4e feat: Version A in Zeile 3 eingetragen
|
||||
* a1b2c3d chore: Vorlage hinzugefügt
|
||||
```
|
||||
|
||||
Der Merge-Commit `f6g7h8i` hat zwei Eltern-Commits (`d4e5f6g` und `e5f6g7h`).
|
||||
|
||||
---
|
||||
|
||||
*Zurück zur [Aufgabe](../04-merge-und-konflikte/aufgabe.md)*
|
||||
Reference in New Issue
Block a user