What's Git
Git is a free and open source distributed version control system
designed to handle everything from small to very large projects with speed and efficiency.
NO!
Git is a distributed file system which is often used as DVCS.
TL; DR
Commit early, commit often
Don't change published history
Moving files
- git add, working directory -> staging area
- git commit, staging area -> repo
- git checkout, repo -> working directory
- git reset
git reset
- soft, changes HEAD
- mixed, changes HEAD and index
- hard, changes HEAD, index and working directory
Revision Selection
- 734713bc047d87bf7eac9674765ae793478c50d3, SHA-1
- HEAD
- HEAD@{0}, reflog
- master@{yesterday}, time
- HEAD^, parent commit
- HEAD^^, parent's parent
- HEAD^2, second parent
- HEAD~, same as HEAD^
- HEAD~2, same as HEAD^^
- master..experiment
- master...experiment
Rewriting History
- git rebase
- git rebase -i
- git commit --amend
- git revert
- git cherry-pick
- git filter-branch
I have an upstream project!
Submodule
- perfect for project you won't touch
- git submodule add
- git submodule init
- git submodule update
- git submodule update --init --recursive
- git submodule foreach git pull
Subtree
- git subtree add
- git subtree merge
- git subtree pull
- git subtree push
- git subtree split
Internal
- Git is fundamentally a content-addressable filesystem with a VCS user interface written on top of it.
Don't Panic when Code is Missing
- Git doesn't lose code you already committed
- Except that .git has been deleted :-(
- Use git reflog and git fsck
git reflog
- shows what have been done recently
- alias for git log -g --abbrev-commit --pretty=oneline
- customizable
git fsck
- find dangling objects
- dangling blob, commit…
- git grep git fsck | grep "dangling commit" | cut -d " " -f 3-
Don't Panic when Regression is Found
- Use git bisect
- Binary search which commit introduces the bug
Find who is responsible
- git blame
- Ask how the code works
- Xcode integration
Working with Gerrit
- git-review
- Chang-Ids
- .gitreview