Wednesday, July 22, 2020

GIT Jumpstart Tutorial For Beginners

GIT Jumpstart Tutorial For Beginners


Introduction


This is an incomplete tutorial for beginners. The tutorial is a quick jumpstart for user who want to learn GIT. This tutorial just cover the very basic things about GIT, it is incomplete.

SVN and CVS



Before you start with GIT, you should know a little bit about CVS or SVN. Basic command like check in (commit) and check out.

$ svn list file:///usr/local/svn/hello
branches/
tags/
trunk/

The trunk is the main repository.
$ svn co file:///usr/local/svn/hello/trunk hello

A hello/README
Note: co is the short form of checkout.

$ svn commit -m "add in description for beginners" README

$ cd hello
$ rm NEWS
$ svn update NEWS (retrieve back news)

The difference between SVN and CVS


CVS. Each file has its own version. SVN, few files may share the same revision number. SVN use atomic commit, eg. commit a few files together, either all success or fail.

GIT vs CVS/SVN


Git is a distributed version-control system, it has its own local repository (can do offline commit/check in). Synchronize with other repositories when the network is available.

Git has 3 stages (server/repository, local/working/untracked and staged/tracked/indexed). CVS and SVN have 2 stages, local/working and the remote repository.

GIT Tutorial


GIT configuration


$ git --version
git version 1.9.5 (Apple Git-50.3) # MacOS Mavericks 10.9
git version 2.20.1 (Apple Git-117) # macOS Mojave 10.14

example:
$ git config --global user.name "fuyichin" (commit with this name)
$ git config --global user.email fuyichin@gmail.com
$ git config --list (shows config)
user.email=fuyichin@gmail.com
user.name=fuyichin
$ git config --global core.editor "vi"

Git init

Create a (local) repository.

$ mkdir hello; cd hello
hello $ git init

create a .git repository at the local directory.

Git status


Create an empty file README.

hello$ touch README
$ git status README

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

README



Git add


Remember there are 3 stages 1. local/untracked 2. tracked/staged/indexed 3. repository in Git. Add files move the file from untracked to tracked (or indexed). Only tracked/indexed files will be committed.

$ git add README; git status README

Changes to be committed:
new file: README

Git commit


$ git commit -m "initial commit" # this commit is a empty README
1 file changed, 0 insertions(+), 0 deletions(-)

Modified the file (the empty file) wit content hello world:
$ echo "Hello, world." > README

$ git status README

modified: README


$ git add README # tracked/indexed hello world
(local change to Hello, John.)

$ git status README

Changes to be committed:
modified: README (Hello, world. tracked)

Changes to the local (untracked) file to "Hello, John":
$ echo "Hello, John." > README
$ git status README

Changes to be committed:
modified: README (Hello, world. tracked)

Changes not staged for commit:
modified: README (Hello, John. local copy, untracked)

When I commit, "Hello, world." will be committed, not "Hello, John". To commit "Hello, John", use git add <file>, this will make local copy to tracked/staged/indexed copy.
$ git commit -m "hello world"

To commit "Hello, John"
$ git add README # add to tracked/staged/indexed
$ git commit -m "hello john"

Git edit last commit


Use Git amend
$ git commit --amend

Git use the EDITOR environment variable or the editor set in 'git config core.editor'.

Git log


Show history
$ git log
$ git log --oneline # easier to read

09d72a7 (HEAD -> master) hello john (amended)
3a0fa58 hello world
7522dee initial commit

What is HEAD and master? HEAD refers to the last commit, master is the master branch. The commit code in-front could be different.

Remove commit


Git commit can be removed or reset before synchronizing to another repository.
09d72a7 (HEAD -> master) hello john # HEAD
3a0fa58 hello world (amended) # HEAD~1, or HEAD^
7522dee initial commit # HEADE~2, or HEADE^^

$ git reset --hard HEAD~1 # 1 commit before HEAD, or
$ git reset --hard 3a0fa58 # this is the commit code
SVN uses revision number, git use commit code as the version identifier.

$ git log --oneline
# 09d72a7 (HEAD -> master) hello john # not displayed
3a0fa58 hello world (amended)
7522dee initial commit

You still can reset back to the original HEAD
$ git reset --hard 09d72a7

$ git log --oneline
09d72a7 (HEAD -> master) hello john
3a0fa58 hello world (amended)
7522dee initial commit

Git configuration: .gitignore


Ignore all the object files, binary files.
$ cat .gitignore
*.o
*.class
a.out

when $ git add * or $ git status, those files listed in .gitignore will be ignored.

Git checkout (files)


Git checkout likes svn update, to retrieve back from the previous copy. The previous copy is either the tracked copy, or from the repository.

$ git checkout [-f] <filename> # or git checkout -- <filename>, or
$ git checkout HEAD <filename> # update from last commit
Note: switch branch use git checkout as well.

Git clone


When you retrieve (a remote) repository, eg. from a server, use git clone. It makes a copy of the repository, including all the history changes to the local working directory.

format: git clone [--depth nn] <repository>

If the git repository is too big, just download the last or last few commit, $ git clone --depth 1 <repository>

Git pull/push


Any commit of changes are updated to the local repository. Use git push to update to the remote repositories. Use git pull to retrieve changes from remote repositories.

Show remote
$ git remote [-v]

Push to remote
$ git push [ origin master]
Push master branch to remote origin. (origin is remote, master is branch)

Working with branch


Working with Git branch is light-weight (compare with CVS, SVN) and easy.

Create branch


Checkout with -b
$ git checkout -b branch1
(This will create branch name branch1 and switch to branch1)

$ git branch [--list?]
Master
* branch1

To switch between master and <branch1>
$ git checkout master
*Master
branch1
$ git checkout branch1

Merge to main branch master.


$ git checkout master
Switched to branch 'master'
Merge
$ git merge branch1

You can delete the branch after it merges to master.
$ git branch -d branch1
This is a safe delete, if the branch code is not merged, git will give a warning. Force delete use -D.

Wednesday, July 08, 2020

Canon CanoScan LiDE Scanner

Canon CanoScan LiDE 20 Scanner



I get a Canon scanner from a friend. It is a very old scanner, but still working. It is a model CanoScan LiDE 20. You can check the specs from CNET here.

When I plugin to my Mac OS X system, it doesn't work, the system is unable to detect the scanner. It is working if you use the VueScan software.

I read from the web, install the Sane software may works. From the supported device lists. The CanoScan LiDE 20 or 30 are supported. (here).

The Sane is an open source project. For Mac package, you can download from http://www.ellert.se/twain-sane/. Too bad I still can't get it works on my Mac system.

Luckily it works on my Linux system, just plug and play!

Just found a CD for the scanner, will try it next time. If you are having the same problem like me, may be you can try the driver from Canon website.

Another software available from CNET Download, here.

Wednesday, July 01, 2020

macOS Switch Input Method With Splash Display

macOS Switch Input Method With Splash Display



This has been bodering me for awhile after I upgraded to macOS Mojave 10.14. The splash display to show different input method is not there anymore.

I like the the splash display to show all the input methods at the center of the display, is large and clear. I don't have to move my eyes to see which input method that I am using now on the menubar, and I can switch between English and Chinese input method easily.

I keep thinking it was a feature included in the third party Chinese Input method that I installed previously, but I can't remember what is the name of the Chinese Input software. Finally I found it, it is Open Vanilla (https://openvanilla.org).

I am still unable to get the splash display to change the input method, even after I installed the Open Vanilla.

Seems like the feature is not from the Open Vanilla. Just enable "Select the previous input source" from Keyboard Shortcut:

macOS > System Preferences > Keyboard > Shortcuts (tab) > Input Sources > (x) "Select the previous input source"


Not I can switch between English and Chinese Input easily.