Day 2
Doing init
Using a freshly init
repo, we are going to do a bunch of small edits to watch how Git conveys information back to the local repo owner.
Create a new repo in a new empty directory -> git init
Create some artifact for git:
touch README.md
git add README.md && git commit -m "Add empty document"
echo "no longer an empty document" > README.md
git commit -am "Second commit" # (szf) Add and commit message on one-line
Here’s where I diverged from the lesson plan and treated my README file like it was a bash script.
Making small edits and several commits, I was able to see the circumstance I created:
From right to left, I have:
- The two commits of my README.md file that has only a single dummy message in the file.
- I started following the buildtools.sh path in Chapter 4. Editing the file to show my intent.
- I have made more edits to the file creating the basis for it to behave as a script.
Commands of Note
git diff
git diff --staged
git add --dry-run .
git log
git log --stat
git log --shortstat --oneline
Expressing my Skillselves
After doing multiple commits, it would seem that doing something unconventional like adding the execute bit to a text file and adding script code should support and inform the commit history.
☝️Using git rebase -i HEAD~N
(where N is positional number), I was able to tag the errant line with the reword
command and change the message in an interactive session. Nice!
Lab
Q. What is another way to call git diff —staged
?
A: git diff —cached
and git diff HEAD README.md
produce the same output
Q. What is the short form of git add . —dry-run
?
A: git add . -n
Q. How do you display line numbers to your file via the cat
command?
A: cat -b
Q. The —oneline
switch that you passed to git log is shorthand for a longer git log command. What is it?
A: git log —pretty=oneline
shows full SHA1 hash
Q. The -a
switch to git commit (to automatically pass files to git add) has a longer alternative switch that is surprisingly not —add
. What is it?
A1: Could be —all
?
A2: You can interactively have git ask what you want to do with a code hunk via git add . -p
for patch mode.