1. What is Git ?
Distributed Version Control System
Git thinks of its data like a set of snapshots of a mini filesystem.
2. Install
Download url for windows:
http://code.google.com/p/msysgit/downloads/list
Install in Linux:
sudo apt-get install git-core
yum install git-core
3. configuration
git help
git help config
git config --global user.name “your name”
git config --global user.email your-email
git config --global core.editor vim
git config --global merge.tool vimdiff
git config --list
4. Repository
Initialize a Repository in local directory:
git init
git add .
git commit –m ‘initial project version’
Clone an existing Repository:
git clone git://10.7.7.10/test/test.git
5. Three main secitons in local git:
Working directory to Staging area:
git status show status in the three sections.
git diff show difference between working directory and staging area.
git add . push all the changed files to staging area.
Git reset HEAD
Staging area to Repository:
git diff --cached/staged show difference between stage and repository.
git commit . Commit changes from staging area to repository.
Repository to Working directory:
git diff HEAD show difference between working directory and Repository
git checkout [filename] rollback file to last committed version
6. Commit
Git generates one SHA-1 HASH for each commit.
Git stores a commit object containing a pointer to the snapshot, author and message metadata, and pointers to parents.
multiple commits:
7. Branch
A branch is a lightweight movable pointer to one commit.
Multiple Branch (master, test)
HEAD: a special pointer to current branch.
git checkout -b testing
git checkout Master
git merge Feature
Fast-Forward
8. gitk
git repostitory browser:
http://www.kernel.org/pub/software/scm/git/docs/gitk.html
9. branch merge conflict, merge tools
when merge two branches, the same part of the same file is different, conflict comes up.
To solve conflict -- git mergetool
http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html
git mergetool –tool=vimdiff [filename]
vimdiff: http://www.ibm.com/developerworks/cn/linux/l-vimdiff/
kdiff3: http://kdiff3.sourceforge.net/
xxdiff: http://furius.ca/xxdiff/
meld: http://meldmerge.org/
tkdiff, gvimdiff, opendiff, emerge……
10. remote
git remote add test git://10.7.7.10/test/test.git
git pull test master
git push test master
git remote show test
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
11. Branch model
12. git log & ignoring files
git log [
http://www.kernel.org/pub/software/scm/git/docs/git-log.html
Using .gitignore file to set up per-project and per-user ignores.
#ignore all file end with .o or .a or ~
http://gitready.com/beginner/2009/01/19/ignoring-files.html
13. git hooks
Hooks -- little scripts in $GIT_DIR/hooks that trigger action at certain points.
applypatch-msg
commit-msg
post-commit
post-receive
post-update
pre-applypatch
pre-commit
pre-rebase
prepare-commit-msg
…
http://www.kernel.org/pub/software/scm/git/docs/githooks.html
14.Git tag & stash
git tag show all tags
git tag –l ‘v1.1.*’ list all tag start with ‘v1.1.’
git tag –d v1.0 delete tag v1.0
git push origin
http://www.kernel.org/pub/software/scm/git/docs/git-tag.html
Save working directory and index state without ‘commit’
git stash
git stash list
git stash apply
http://www.kernel.org/pub/software/scm/git/docs/git-stash.html
15. git debug
“git blame” to see when each line of specified file was last edited and by whom.
“git bisect” to identify which commit introduced issue.
http://www.kernel.org/pub/software/scm/git/docs/git-bisect.html
16. Don’t use a screwdriver like a hammer
With enough flags you can force Git to act the way you think it should instead of the way it wants to.
But that’s like using a screwdriver like a hammer.
refs:
http://sandofsky.com/blog/git-workflow.html
http://gitready.com/
http://www.kernel.org/pub/software/scm/git/docs/
http://book.git-scm.com/