We'll now experiment with various commands which form a basic workflow
After each step view the status with git status
# 1. create a file with content
echo "one" > numbers.txt
# 2. stage the file (add it to the index)
git add . # or you can use git add numbers.txt
# 3. unstage the file (remove it from the index) - git gives you a massive hint as to how to do this!
⌛ We'll pause here for more discussion
# 1. Add the file to the staging area again
# 2. Create a commit with the message "first commit"
git commit -m "first commit"
[main (root-commit) 55e1343] first commit
1 file changed, 1 insertion(+)
create mode 100644 numbers.txt
[<branch> (root-commit) <commit hash>] <commit message>
1 file changed, 1 insertion(+)
create mode <file permissions code> numbers.txt
# view the working tree
git ls-tree -r HEAD
100644 blob 5626abf0f72e58d7a153368ba57db4c673c0e171 numbers.txt
git cat-file -p 5626abf0f72e58d7a153368ba57db4c673c0e171
git show <commit hash>
commit 55e1343833c4c73f4792ce642a585127d0abf05d (HEAD -> main)
Author: AliciaMoses <email>
Date: Mon Apr 1 03:33:48 2024 +0100
first commit
diff --git a/numbers.txt b/numbers.txt
new file mode 100644
index 0000000..5626abf
--- /dev/null
+++ b/numbers.txt
@@ -0,0 +1 @@
+one
(END)
git log --graph --oneline
⌛ We'll pause here for more discussion
echo "two" >> numbers.txt
echo "three" >> numbers.txt
git diff numbers.txt
git status -s
git stash
git stash list
git stash apply stash @{n} # in our case it's 0
git stash
git stash pop
git reset --hard
git stash list
git clean -df
git branch my-branch
git branch their-branch
git checkout my-branch
git log --graph --oneline
echo "three" >> numbers.txt
git add .
git commit -m "third commit on my-branch"
git checkout their-branch
echo "3" >> numbers.txt
git add .
git commit -m "third commit on their-branch"
git checkout my-branch
git merge their-branch
Auto-merging colours.txt
CONFLICT (content): Merge conflict in numbers.txt
Automatic merge failed; fix conflicts and then commit the result.
echo "rectangle" >> shapes.txt
echo "A" >> letters.txt
git add -p
git log --graph --oneline
git checkout main
git checkout my-branch
git merge main
echo "B" >> letters.txt
git add .
git commit -m "Add letter B to letters.txt"
git checkout main
git merge my-branch
git log --graph --oneline
git show HEAD
git show HEAD^
* f94db50 (HEAD -> main, my-branch) Add letter B to letters.txt
* 5e678d0 Merge branch 'main' into my-branch
|\
| * 42ef31c another new commit on main
| * 6c89df7 new commit on main
* | 0e12a9b Merge branch 'their-branch' into my-branch
|\ \
| * | fea224c (their-branch) third commit on their-branch
| |/
* / 78b3555 third commit on my-branch
|/
* f596643 second commit
* 55e1343 first commit
~
git reset --hard HEAD^
HEAD is now at 5e678d0 Merge branch 'main' into my-branch
git reflog
git reflog --date=iso
git reflog --relative-date --all