Git Introduction and basic operations

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 <verb> use this command to get help on your own.
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 <filename> unstage file

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 [<options>] [<since>..<until>] [[--] <path>

 

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 <tag name> push tag to remote

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/

 

 

 

 

转载于:https://www.cnblogs.com/Alex-Python-Waiter/archive/2012/08/19/2646458.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值