SSE2034: System Software Experiment 3 Spring 2016 Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu
git Distributed version control system
git tutorial User setup Create repository Commit Multi version History New Clone Commit Multi version Branch, checkout, etc. History Log, diff, etc.
User Setup git config --global user.name ”user name” git config --global user.email you@yourdo main.example.com
New Repository Create new repository mkdir ~/source_code cd ~/source_code git init JeongHwanjinui-MacBook-Air:~ Hwanjin$ mkdir ~/source_code JeongHwanjinui-MacBook-Air:~ Hwanjin$ cd source_code/ JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git init Initialized empty Git repository in /Users/Hwanjin/source_code/.git/ JeongHwanjinui-MacBook-Air:source_code Hwanjin$ ls -al total 0 drwxr-xr-x 3 Hwanjin staff 102 5 17 17:20 . drwxr-xr-x+ 36 Hwanjin staff 1224 5 17 17:19 .. drwxr-xr-x 10 Hwanjin staff 340 5 17 17:20 .git
Clone Repository Local clone Remote clone git clone ~/source_code Remote clone git clone userid@host:~/source_code Ex) git clone https://github.com/hwanjinje ong/emacs_config CS258 S99
commit git add <file name> or * git commit –m “message” add mv Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git add * JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git commit -m "first commit" [master (root-commit) 0c9021e] first commit
Pull & Push Push your committed changes to the rem ote master repository Pull changes pushed to remote master int o your local copy
Pull & Push git push <local> <remote> git pull Ex) git push origin master git pull
Branch Grow, mark and tweak common history
Branch JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch * master JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch test JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch test1 test test1 JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch -d test1 Deleted branch test1 (was 0c9021e). JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch * master test
Checkout
Checkout JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git branch master * test JeongHwanjinui-MacBook-Air:source_code Hwanjin$ ls -al test_file -rw-r--r-- 1 Hwanjin staff 5 5 17 17:44 test_file JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git checkout master Switched to branch 'master' -rw-r--r-- 1 Hwanjin staff 0 5 17 17:45 test_file JeongHwanjinui-MacBook-Air:source_code Hwanjin$
History - log git log JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git log commit 6029ac48c225494129414e59bb3a5cfa47c493d2 Author: Hwanjin Jeong <Hwanjin@JeongHwanjinui-MacBook-Air.local> Date: Tue May 17 17:44:10 2016 +0900 test commit 0c9021ea35fa43875444f6e203f436586ad92d28 Date: Tue May 17 17:27:42 2016 +0900 first commit
History - diff git diff <commit log id> JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git diff 0c9021ea35fa43875444f6e203f436586ad92d28 diff --git a/test_file b/test_file index e69de29..9daeafb 100644 --- a/test_file +++ b/test_file @@ -0,0 +1 @@ +test
Reset git reset --hard <commit log id> JeongHwanjinui-MacBook-Air:source_code Hwanjin$ ls -al test_file -rw-r--r-- 1 Hwanjin staff 5 5 17 17:46 test_file JeongHwanjinui-MacBook-Air:source_code Hwanjin$ git reset --hard 0c9021ea35fa43875444f6e203f436586ad92d28 HEAD is now at 0c9021e first commit -rw-r--r-- 1 Hwanjin staff 0 5 17 17:49 test_file
Github https://guides.github.com/activities/hello- world/#repository