Git in class

Create a Repository

Follow https://swcarpentry.github.io/git-novice/03-create/index.html with some changes

[1]:
rm -rf   /home/jovyan/work/planets/
mkdir -p /home/jovyan/work/planets/
cd /home/jovyan/work/planets/
pwd
/home/jovyan/work/planets
[2]:
git init
Initialized empty Git repository in /home/jovyan/work/planets/.git/

Setting Up Git

[3]:
git config user.name "Vlad Dracula"
git config user.email "vlad@tran.sylvan.ia"
[4]:
ls
[5]:
ls -a
.  ..  .git
[6]:
git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
[7]:
mkdir moons
ls
moons
[8]:
git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

Tracking Changes

[9]:
pwd
/home/jovyan/work/planets
[10]:
cat > mars.txt << EOF
Cold and dry, but everything is my favorite color
The two moons may be a problem for Wolfman
EOF
[11]:
ls
cat mars.txt
mars.txt  moons
Cold and dry, but everything is my favorite color
The two moons may be a problem for Wolfman
[12]:
git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        mars.txt

nothing added to commit but untracked files present (use "git add" to track)
[13]:
git add mars.txt
[14]:
git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   mars.txt

[15]:
git commit -m "Start notes on Mars as a base"
[master (root-commit) 1fbe642] Start notes on Mars as a base
 1 file changed, 2 insertions(+)
 create mode 100644 mars.txt
[16]:
git status
On branch master
nothing to commit, working tree clean
[17]:
git log
commit 1fbe6424cf9dc240f2540ce6877646467214bca6
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:25 2019 +0000

    Start notes on Mars as a base
[18]:
echo 'The two moons may be a problem for Wolfman' >> mars.txt
[19]:
git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   mars.txt

no changes added to commit (use "git add" and/or "git commit -a")
[20]:
git diff
diff --git a/mars.txt b/mars.txt
index 315bf3a..6b1d81a 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,2 +1,3 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
+The two moons may be a problem for Wolfman
[21]:
git commit -m "Add concerns about effects of Mars' moons on Wolfman"
On branch master
Changes not staged for commit:
        modified:   mars.txt

no changes added to commit

[22]:
git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   mars.txt

no changes added to commit (use "git add" and/or "git commit -a")
[23]:
git add mars.txt
git commit -m "Add concerns about effects of Mars' moons on Wolfman"
[master bbb518b] Add concerns about effects of Mars' moons on Wolfman
 1 file changed, 1 insertion(+)
[24]:
echo But the Mummy will appreciate the lack of humidity >> mars.txt
[25]:
git diff
diff --git a/mars.txt b/mars.txt
index 6b1d81a..9ceb94e 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,4 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
+But the Mummy will appreciate the lack of humidity
[26]:
git add mars.txt
[27]:
git diff
[28]:
git diff --staged
diff --git a/mars.txt b/mars.txt
index 6b1d81a..9ceb94e 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,4 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
+But the Mummy will appreciate the lack of humidity
[29]:
git commit -m "Discuss concerns about Mars' climate for Mummy"
[master 12100d9] Discuss concerns about Mars' climate for Mummy
 1 file changed, 1 insertion(+)
[30]:
git status
On branch master
nothing to commit, working tree clean
[31]:
git log
commit 12100d9076a11b9b9c14b74f89e35f37b17d2290
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:37 2019 +0000

    Discuss concerns about Mars' climate for Mummy

commit bbb518b1021fa00ce43649ae1536929eafe08f8d
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:33 2019 +0000

    Add concerns about effects of Mars' moons on Wolfman

commit 1fbe6424cf9dc240f2540ce6877646467214bca6
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:25 2019 +0000

    Start notes on Mars as a base
[32]:
mkdir spaceships
git status
On branch master
nothing to commit, working tree clean
[33]:
git add spaceships
git status
On branch master
nothing to commit, working tree clean
[34]:
touch spaceships/apollo-11 spaceships/sputnik-1
git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        spaceships/

nothing added to commit but untracked files present (use "git add" to track)
[35]:
git add spaceships/apollo-11
[36]:
git add spaceships/sputnik-1
git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   spaceships/apollo-11
        new file:   spaceships/sputnik-1

[37]:
git commit -m "Add some initial thoughts on spaceships"
[master b84b48a] Add some initial thoughts on spaceships
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 spaceships/apollo-11
 create mode 100644 spaceships/sputnik-1
[38]:
ls spaceships
apollo-11  sputnik-1

Exploring History

[39]:
echo An ill-considered change >> mars.txt
[40]:
git diff HEAD
diff --git a/mars.txt b/mars.txt
index 9ceb94e..0fee1c3 100644
--- a/mars.txt
+++ b/mars.txt
@@ -2,3 +2,4 @@ Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
 But the Mummy will appreciate the lack of humidity
+An ill-considered change
[41]:
git diff HEAD~2 mars.txt
diff --git a/mars.txt b/mars.txt
index 6b1d81a..0fee1c3 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,5 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
+But the Mummy will appreciate the lack of humidity
+An ill-considered change
[42]:
git diff HEAD~3 mars.txt
diff --git a/mars.txt b/mars.txt
index 315bf3a..0fee1c3 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,2 +1,5 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
+The two moons may be a problem for Wolfman
+But the Mummy will appreciate the lack of humidity
+An ill-considered change
[43]:
git show HEAD~2 mars.txt
git show HEAD~3 mars.txt
commit bbb518b1021fa00ce43649ae1536929eafe08f8d
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:33 2019 +0000

    Add concerns about effects of Mars' moons on Wolfman

diff --git a/mars.txt b/mars.txt
index 315bf3a..6b1d81a 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,2 +1,3 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
+The two moons may be a problem for Wolfman
commit 1fbe6424cf9dc240f2540ce6877646467214bca6
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Date:   Wed Jun 26 08:04:25 2019 +0000

    Start notes on Mars as a base

diff --git a/mars.txt b/mars.txt
new file mode 100644
index 0000000..315bf3a
--- /dev/null
+++ b/mars.txt
@@ -0,0 +1,2 @@
+Cold and dry, but everything is my favorite color
+The two moons may be a problem for Wolfman
[44]:
git diff HEAD~2 HEAD~3
diff --git a/mars.txt b/mars.txt
index 6b1d81a..315bf3a 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,2 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
-The two moons may be a problem for Wolfman
[45]:
git diff bbb51 1fbe64
diff --git a/mars.txt b/mars.txt
index 6b1d81a..315bf3a 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,2 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
-The two moons may be a problem for Wolfman
[46]:
git diff bbb51 mars.txt
diff --git a/mars.txt b/mars.txt
index 6b1d81a..0fee1c3 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,3 +1,5 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
+But the Mummy will appreciate the lack of humidity
+An ill-considered change
[47]:
git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   mars.txt

no changes added to commit (use "git add" and/or "git commit -a")
[48]:
git checkout -- mars.txt
[49]:
cat mars.txt
Cold and dry, but everything is my favorite color
The two moons may be a problem for Wolfman
The two moons may be a problem for Wolfman
But the Mummy will appreciate the lack of humidity
[50]:
git checkout bbb51 mars.txt
[51]:
cat mars.txt
Cold and dry, but everything is my favorite color
The two moons may be a problem for Wolfman
The two moons may be a problem for Wolfman
[52]:
git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   mars.txt

[53]:
git diff --staged mars.txt
diff --git a/mars.txt b/mars.txt
index 9ceb94e..6b1d81a 100644
--- a/mars.txt
+++ b/mars.txt
@@ -1,4 +1,3 @@
 Cold and dry, but everything is my favorite color
 The two moons may be a problem for Wolfman
 The two moons may be a problem for Wolfman
-But the Mummy will appreciate the lack of humidity
[54]:
git checkout HEAD mars.txt
[55]:
git status
On branch master
nothing to commit, working tree clean
[56]:
git checkout 1fbe64 mars.txt
[57]:
git checkout 1fbe64
Note: checking out '1fbe64'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 1fbe642... Start notes on Mars as a base
[58]:
git checkout master
Previous HEAD position was 1fbe642... Start notes on Mars as a base
Switched to branch 'master'
[59]:
git status
On branch master
nothing to commit, working tree clean