Git for fun and profit
(but mostly profit)
Commits
- The more often you commit the better
- They are not just changes to the files
- With a single commit you can restore all files
Log
git log -3
git log --after="2014-7-1" --before="2014-7-4"
git log --graph --abbrev-commit --decorate --date=relative
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)
%s%C(reset)%C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
* de1f274 - (26 hours ago) refactor: made move_piece function void - Bloodcount
* 907c5ae - (26 hours ago) feat: added notion of turns - Bloodcount
* 2448657 - (3 days ago) feat: finished implementing the game turns- Bloodcount
Log
git log --graph --abbrev-commit --decorate
--format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)
(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)
- %an%C(reset)' --all* 51f1ece - Sun, 10 May 2015 22:19:52 +0300 (25 hours ago)
| refactor: changed way of getting piece owner - Bloodcount
* 83cd472 - Sun, 10 May 2015 22:19:08 +0300 (25 hours ago)
| feat: added possible moves for piece function - Bloodcount
Bare repositories
- Basically repositories which you can clone and push too.
- Cloned repositories aren't bare by default
git init --baregit clone --bare /home/bare_repo #local address are fine too!Now you can push/pull from the bare repo.
Git is decentralized
master (bare)
slave
slave
slave
But this is not...
Decentralization
master (bare)
clone
clone (bare)
clone
clone
clone
Decentralization raises complexity!
- Think carefully before you use it
- Usually shows bad design
- You can always use branches
Tagging
git taggit tag # list tags
git tag -l 'v1.8.5*' # list all tags starting with v1.8.5
git tag -a v1.42 #anotated tab
tag v1.42
Tagger: foobar
Date: Sat May 3 12:20:12 2014 -0700
my version 1.42
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 13:52:11 2008 -0700
changed the version number
git tag v1.4-lw #lightweight tag
commit ca82a6dff817ec66f44342007202690a93763949
Author: foobar
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version numberTagging
Tags aren't commited by default!
git push origin --tags
git checkout -b [branchname] [tagname] #checkout tagBranches
- Share history
- Can be merged
- The main idea is to split the work into smaller tasks
Branches
git checkout -b branch_a #create a new branch
git branch #list all branches
* brancha
master
new_branch
git checkout master #go back to master branch
brancha
* master
new_branch
git fetch #to pull for a single branchTagging vs Branches
- You can achieve the same things with both approaches
- It's a personal preference, though branches are more popular
- Note that branches require more space than tags
Questions ?
Git for fun and profit(but mostly profit)
By Zlatin Stanimirov
Git for fun and profit(but mostly profit)
- 811