Tuesday, September 12, 2017

Git Examples and Notes


Git Notes and Examples

Where to Get Git?

You can download Git from git-scm.com/downloads

Tools

You can download a visual GUI for Git at www.atlassian.com/software/sourcetree.

"gitk" is a handy GUI tool installed with some systems.

Documentation

Scott Chacon's and Ben Straub's book, ProGit is downloadable for free at git-scm.com/book/en/v2

Atlassian has a great tutorial at www.atlassian.com/git/tutorials

An interesting interactive visual demo of Git is at https://onlywei.github.io/explain-git-with-d3/#push

Git from the Bottom Up: https://jwiegley.github.io/git-from-the-bottom-up/

Getting Started

git init
creates .git directory and machinery to create a git repository
git clone https://github.com/jquery/jquery.git
clones (copies) repo and creates a local repository with all the commits, trees, blobs, branches, and tags, but not the remotes. For that use the "-mirror" switch.
git clone presidents presidents1
copies repo "presidents" to "presidents1".

checkout

git checkout -b newBranch
create a new branch from the current branch. It is equal to doing a "git branch newBranch" and then a "git checkout newBranch"
git checkout MyBranch
set the current branch to "MyBranch"
git checkout -- my-file.txt
checkout a copy of "my-file.txt" from the current branch and overwrite the current copy.
git checkout 661d5fd32
detach the HEAD and set directly to a commit
git checkout -
checkout previous branch used

What's Going On?

git status
shows your current branch and any interesting files
git status --short
shorter list with first two cols significant
git config --list
show all settings; and from ~/.gitconfig
git log
see the changes
git log --oneline
to show quick one line summary
git log -2
see last two changes
git branch
shows all your local branches
git branch -r
shows all remote branches
git branch -a
shows all remote and local branches
git branch -vv
shows a verbose last commit on each branch
git branch --merged
shows all branches that have been merged
git branch --no-merged hashid
lists branches that have not been merged i.e., list branches whose tips are not reachable from the hashid (HEAD is used if hashid not specified)
git branch newBranch
create new branch named "newBranch"

Deep Magic Commands

git cat-file -t 5f831d630dd0
returns the type of the object, like "blob","commit","tree", or "tag"
git cat-file type hash id
shows the contents of the file pointed to by the hash id
   git cat-file blob 5f831d630dd069aca58b3a164ff526b53c142456
'Hello, world!'
   
git cat-file commit a7cc8785c5bd3594c9659b779ed56487097281b4 //shows the contents of a commit with two files, "texas" and "greeting":
tree a822836950b935d16f8ee572429dd1d754a85a73
parent 640f3af9f9e883a5ed0102154e453170f04267b7
author Mitchell Fincher <mitchell.fincher@fincher.org> 1505507251 -0500
committer Mitchell Fincher <mitchell.fincher@fincher.org> 1505507251 -0500

texas greeting
  
git ls-tree hashid
show all the objects in the commit pointed to by a tree.
  git ls-tree master
100644 blob 5f831d630dd069aca58b3a164ff526b53c142456    greeting
100644 blob b6d99afd00cffebbd33e6a99c946e4bf54319ec4    texas  
git hash-object file1.txt
show the SHA1 hash created by the contents of file1.txt
git ls-files
show info about the files on the stage (index)
git rev-parse HEAD
HEAD is usually a reference to a branch which contains a pointer to a commit. "rev-parse" derefences the branch and shows the hash id of the commit without having to go through the intermediate branch.
git rev-parse HEAD
3a9aae03b78bb617e9ec7822289e4a991ea7c2d8

cat .git\HEAD
ref: refs/heads/master

λ cat refs/heads/master
3a9aae03b78bb617e9ec7822289e4a991ea7c2d8
git write-tree
takes the contents of the index and creates a tree
echo "My comment" | git commit-tree hashid
commit-tree takes a tree hashid and creates a comment from it
git update-ref refs/heads/master hashid
writes the hashid into the file refs/heads/master, making that commit hashid the current one for the branch master. This can be done manually:
echo hashid > .git/refs/heads/master
git symbolic-ref HEAD refs/heads/master
sets the value in .git/HEAD to be "refs/heads/master". You can try to do it manually with "echo", but it will put a space at the end of the line. To do this manually you should edit in your fav editor.
echo ref: refs/heads/branch1> .git\HEAD
C:\Users\mfincher\gittest (master ) #notice space at the end

Misc

git remote update origin --prune
removes from your local list the branches that have been deleted in origin
git ls-files
show all the files in the repo

Help Me

git help
get general help
git help config
get help on the "config" command

Adds and Commits

git rm '*.txt'
stage the removal of all the txt files
git add file1.txt
adds file to the stage
git add file1.txt file2.txt
adds files to the stage
git add '*.txt'
adds wildcards, but must have single quotes
git add --all
adds all new, deleted or modified files
git add -A
stages All
git add .
stages new and modified, without deleted
git add -u
stages modified and deleted, without new
git commit -m "my commit message"
commit staged files to repo

Remoting

git remote add origin https://github.com/try-git/try_git.git
adds a remote location with the name of "origin" and points it to the URL. This creates a shorthand name for the URL.
git remote set-url origin git@github.com:User/UserRepo.git
changes a remote location's value
git push -u origin master
pushes your code to the master branch of the repo defined by "origin"

What's Changed

git diff
see changes you've made, defaults to HEAD
git diff HEAD
see changes you've made
git diff {branchName}
see changes between current branch and {branchName}
git diff --staged
what has changed in the staged area
git diff commitid
see changes from commitid

Reset

git reset file1.txt
removes file1.txt from the staging area
git reset --hard eb70244
sets HEAD to specific commit and erases all changes in current working tree. Use "git checkout eb70244" to preserve changes.
git reset HEAD^
undoes last commit and leaves files ready to be staged
git reset origin/master
restore to origin's version

Merge

git merge MyBranch
merges changes from MyBranch into current branch. The current branch is updated, but the target branch, "MyBranch", is unaffected. Typical flow with no conflicts:
  git checkout master
  git checkout -b feature1
  # make edits and commits on feature1
  git checkout master
  git merge feature1
  git branch -d feature1

Deleting

git branch -d feature3
delete branch feature3
git clean -df
delete untracked files

Push

git push
pushes local changes to origin
git push -f
forces local changes to origin overwriting others changes. Not recommended except in extreme cases.

Rebase

git rebase -i HEAD~3
to go back three commits, note lines in reverse order now
git rebase --abort
stop the rebase and roll back

Stash - store changes off to the side

git stash save
stashes staged and unstaged changes onto stash queue and revert current branch to last commit
git stash save "message"
stash to a name
git stash
appends "save" at the end for you
git stash apply
brings back the stash
git stash list
shows list of stashes with previous commit
git stash list --stat
show more info, log options can be used e.g., "--oneline"
git stash apply stash@{1}
brings back stash 1. Does not pop off the top of the queue - leaves it there
git stash drop
removes top stash frame in queue
git stash pop
gets top stack and drops it
git stash save --save-index
keeps staged files, but stashes unstaged
git stash show
shows info on last stash
git stash show stash@{2}
info on 2
git stash clear
removes all stashes

Cherry Picking

git cherry-pick 52312e5
will pick that commit into our current branch
git cherry-pick --edit 52312e5
allows changing message
git cherry-pick --no-commit 5321235 55aed374
pulls in changes to staging
git cherry-pick -x 5321
adds in previous sha number in comments
git cherry-pick --signoff 5321
adds picker's id

Genealogy, Searching the Family Tree

a3d5fca12
to reference a commit you only need to type enough characters to make it unique, usually 6 or 7 characters are enough.

Notes

HEAD is usually a symbolic reference to the last commit in the currently checked-out branch. HEAD points to the current branch. In the .git directory, the file "HEAD" contains a pointer to the current branch, which in turn references a commit hash id. Example:

cat .git/HEAD
ref: refs/heads/Mitch_895553_MyBranchName

 cat .git/refs/heads/Mitch_895553_MyBranchName
a3d5fc559d4ba4183964ca6d17e658812eafb141

The HEAD can be set directly to a commit. This is called a "detached head".

A directory named "index" holds all the files to be committed. This is called the "stage", where files are staged before being committed. Files do not go from the working tree to the repository, they have to be added to the staging area first with a "git add " command.

The "working tree" is where the normal files are kept on your filesystem. It has a ".git" directory which contains all the .git objects.

A "commit" is a snapshot of the working tree.

A "tag" points to a commit, has a description, but unlike a branch it never moves.

A "blob" is a compressed file with no meta-data. All the meta-data like name are stored in the tree. It may, and probably is, referenced by many trees.

A "hash id" is a SHA-1 hash, a 40 character hex hash. SHA-1 takes text and reduces it down to 40 characters. See "git hash-object file".

Almost all operations in Git add data to the db, it doesn't delete or change the database, so it's very forgiving

~/.gitconfig has my local config options like username

For passwords setup in Visual Studio, see: https://www.visualstudio.com/docs/git/set-up-credential-managers

Emacs Examples and Notes

Emacs Examples and Notes

This is the start of my Emacs notes - more to come.

Keyboard Macros

C-x C-k n
names last keyboard macro only for session
C-x C-k b
bind to key sequence
M-x insert-kbd-macro CR macroname CR
inserts named keyboard macro into current file, e.g., .emacs

Tuesday, July 18, 2017

Windows 7 is Not Recognizing a USB Keyboard


My Windows 7 box has not been recognizing my awesome USB Das Keyboard when I dock my workstation in the morning.  The solution was to update the power settings so Windows would not ignore USB devices after powering down.

Steps to Fix:
1. From the Start Button, select "Control Panel" and then "Power Options"



2. Select "Change plan settings" from your favorite power plan.

3.  Select "Change advanced power settings"

4. And finally set the "USB selective suspend setting" to "Enabled".

5.  This should force Windows to keep the USB ports active and recognize your devices.  It may take a minute when you dock your laptop for it to recognize the keyboard.  Please be patient.  This is windows.

Wednesday, July 05, 2017

iPhone "Cannot Connect to App Store"

My iPhone could not connect to the App Store this morning.  I checked Apple Supports answer, but that didn't solve it.

I got these two errors  "Cannot Connect to App Store" and "Loading":

The problem turned out to be my local Wi-Fi provider was blocking ports.   The solution is to switch off your Wi-Fi and access the App Store via cellular - assuming you have enough data in your plan.


Saturday, June 10, 2017

Cutting the Cable in Austin TX with a Tivo and Digital Antenna

After spending around $12,240 on cable TV for the past 17 years, I finally decided to join the 2nd millennium and say goodbye to my cable company and hello to digital broadcast TV.

Here's my step by step guide to cutting the cord on cable with a Tivo in Austin TX. 

1.  Find out if you can receive any digital TV signals.  Visit the FCC at www.fcc.gov/media/engineering/dtvmaps and see how many stations you can receive.  Here's what Austin looks like.




2. Purchase a few digital antennas and see which one works the best and take the rest back.  The price has nothing to do with quality.  Antennas may be actively powered or passive.  The powered may be better for far away stations, but they may not be good for close stations.  Consumer Reports tried to recommend specific brands, but after testing, they could not recommend any since the antennas would do well in one area, but not another.  At the recommendation of the Best Buy guy I tried this one which costs $33.  See more notes below on antennas.
 3. Mount the antenna on the wall near your TV, or better yet on an interior window.

4 Hook up your antenna to the back of your Tivo.

5. Convert the Tivo from cable to over the air (OTA).
The tricky part with the Tivo is that you have to go through the complete initial setup again. On the main menu select "Settings and Messages"/"Help"/"Restart or Reset"/"Repeat Guided Setup" to repeat the setup.  Select "Antenna only" on all the settings.
Tivo will then scan your antenna and show you all the stations it found.

 6.   Remove poor quality stations.
Tivo found 20 OTA stations, but not all came in well and many were in Spanish.
After subtracting those , I now have these stations in Austin TX:
18-1 PBS
18-2 create
18-3 PBS
18-4 PBS
21-1 ABC
24-3 Justice
36-1 NBC
36-2 COZI
36-3 ION
42-1 CBS
54-1 CW
54-2 GRIT
54-3 Laff

 7. Make sure everything is working correctly and then call the cable company to cut the cord.

My bill went from $150 to $ $90 with taxes.
That is still way too high for just internet at 100Mb, but it's a start.
How much do you pay for internet and phone?

Epilogue:
After trying the RCA antenna for a while I was disappointed.  I took that back to Best Buy, and  I got a better cheaper one ($20) from Amazon: the Mohu Leaf Metro TV Antenna, Indoor, Portable, 25 Mile Range. It works much better.
Then for my other TV I tried the Intoam Leaf, but it could only pick up 10 stations clearly.


Friday, June 09, 2017

Agile Austin Lean / Kanban SIG Group Lunch Meeting - Theory of Constraints

Jim Brission from Agilecoaching.org gave a great noon talk to the Agile Austin Lean / Kanban SIG group.




Jim started by showing I Love Lucy's famous chocolate scene


My Notes::
Recommended book:  The Goal


Intro:  In hiking you can only go as fast as your slowest person.

Process of Ongoing Improvement (POOGI)

1. Identify system's constraint
   (Optimizing other steps is a waste)
2. Maximally exploit the constraint
3. Subordinate every else
4. Elevate Constraint fix it, make it faster
5. Iterate

Where do we see constraints in Software Development?
Any handoff - QA, Technical Writer, Release team
That guy
  - knows the device driver, the kernel
  - is a super debugger

Drum-Buffer-Rope

Drum sets the beat
Buffer is inventory
Rope pulls work into stockpile

Double Loop Learning
  Action Strategies / Results & Consequences
  Governing Variable (values, assumptions, frameworks, beliefs)

Critical Chain Project Management - CCPM
Start with
  Network of tasks and dependencies
  Estimates
Order
  No task starts before dependencies met
  No multitasking of individuals
  Minimize Project Duration

Buffer: Time, Money, Scope
Put buffer at the end of a project, not in individual tasks.

Fever chart

Product owner can save the day by paring down the scope

Cost Accounting
  Created after industrial revolution
  Measures efficiency of men adn machines - unit production per dollar of man or machine
  Cost Accounting not good for software development
 
ABC - Activity Based Costing
Invalid Assumptions
  Local efficiencies lead to global efficiency
  (.e.g, making one machine faster, doesn't necessarily help the throughput - unless its the most constrained operation)
Bad things that are viewed as good things in Cost Accounting
  Build up inventory (keep machines/people busy)
  Fill everyone's plate with work
    or minimize personnel to ensure all are fully engaged
  Show high productivity rather than high value


Tuesday, June 06, 2017

Agile Austin "Attacking Things Incrementally"

Walter Bodwell spoke to 55 people at Agile Austin this month.

 
Yassar opened the meeting






 Walter was a great speaker.  He made the audience feel comfortable and people participated well.  We broke into small groups and discussed how to break down some current issues we had at work.

Here's my personal notes:

Simplicity the art of maximizing the amount of work not done is essential.
Small stories are best:  easier to estimate, enables earlier testing, less risk, faster feedback, easier to pivot, easier to tell when done.
Stories can be too small - overhead can be too big.
At least 5-9 stories per iteration.
Ideally .5 to 3 days  per story.

Barriers to small stories: get past all or nothing; some developers don't want to itemize large tasks, overhead can be too great.

 When splitting a story each "slice" should add incremental user value.
Reprioritize and resize after splitting

Who does the splitting?  Product owners and developers
Split stories vertically (Ui and Middle Tier and DB) so user can see value
Don't split horizontally e.g., DB, because user can't see value or be tested

Questions to ask yourself:
How will we test this slice?

Ideas for splitting:
Handle most important users first
CRUD - Start with just Create and Read; wait on Update and Delete
Do the happy path first
Make it work, make it work fast

Why Small Releases?:  Easier to defer to next release; earlier revenue opportunity; earlier feedback; pivot faster;

When doing a code rewrite, put both system out so users can still use old system.  Sometimes a feature is written in such a way that a customer can do something odd and create something very valuable to them which is not documented nor was it intended.