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.

Git Introduction and basic operations_第1张图片

 

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 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:

Git Introduction and basic operations_第2张图片

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 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.

Git Introduction and basic operations_第3张图片

multiple commits:

Git Introduction and basic operations_第4张图片

 

7. Branch

A branch is a lightweight movable pointer to one commit.
Multiple Branch (master, test)
HEAD: a special pointer to current branch.

Git Introduction and basic operations_第5张图片

git checkout -b testing

Git Introduction and basic operations_第6张图片Git Introduction and basic operations_第7张图片

git checkout Master

git merge Feature

Git Introduction and basic operations_第8张图片

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

Git Introduction and basic operations_第9张图片

 

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 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 Introduction and basic operations_第10张图片

 

“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

你可能感兴趣的:(git,运维,开发工具)