#!/usr/bin/bash

unset LANG

# Git requires a first-time setup
# Non permanent configuration through environment variables
export GIT_COMMITTER_NAME="Holger Obermaier"
export GIT_COMMITTER_EMAIL="Holger.Obermaier@kit.edu"
export GIT_AUTHOR_NAME="Holger Obermaier"
export GIT_AUTHOR_EMAIL="Holger.Obermaier@kit.edu"

# Initialize an empty Git repository
mkdir myFirstRepository
cd    myFirstRepository
git init
# * Creates hidden directory .git
# * Git objects and references are stored in .git

# Review status of the repository
git status

# Create file helloWorld.c with the editor of choice
cat > helloWorld.c <<'EOF'
int main(int* argc, char *argv[]) {
    printf("Hello World\n");
}
EOF

# Review status of the repository
git status

# * Commits are prepared in the staging area (also called cache or index)
# * Multiple changes can be staged before a commit
# * Only staged changes are part of a commit. Unstaged changes are ignored
# * Add file helloWorld.c to the staging area
git add helloWorld.c

# Review status of the repository
git status

# Commit changes to repository
git commit -m "Add hello world"

# Review status of the repository
git status

# Review history on the current branch
git log

# * git log shows flattened history ignoring graph structure of repository
# * git log --all --decorate --graph shows history with graph structur

# Modify file helloWorld.c with the editor of choice. Add missing include directive
cat > helloWorld.c <<'EOF'
#include <stdio.h>

int main(int* argc, char *argv[]) {
    printf("Hello World\n");
}
EOF

# Review status of the repository
git status

# Review changes of modified files
git diff

# Directly commit changes to repository, without using staging area
git commit -m "Added missing include directive" helloWorld.c

# Review history on the current branch
git log

# Show changes made in the commit
git show 94a7050b5e43d3c05571dae49176e747c0b9a782
git show HEAD

# Return to a previous commit
git checkout 5814cdae3c0e87cda36fb6de0f17a3efdb3dd872
git checkout master

# Remove files, directories or links in the repository
git rm helloWorld.c

# Restore a modified file
git restore helloWorld.c

# Move / rename a file, directory or link in the repository
git mv helloWorld.c HelloWorld.c

# Search in the repository
git grep Hello
