Git是Linus Torvalds领导开发的分布式版本管理系统,也是世界上最流行的分布式版本管理系统。关于Git,这里有一本非常好的学习资料[中文版][progit-chinese]和[英文版][progit-english]。下面是最常用的一些命令。
Init
1 | # init a repository with working tree |
Clone
1 | # clone from an existing repository |
Add
1 | # add a file 'file' to staging area |
Status
1 |
|
Commit
1 | # commit changes of the working tree in the staging area to local repository |
Log
1 | # show commit history |
Remove
1 | # remove file from working tree and mark it as removed in staging area |
Reset
1 | # reverse to 'git add <file>', move the changes of 'file' out of staging area |
Revert
1 | # drop all changes of 'file' after last commit |
create a branch ‘new-branch’
git branch
switch to a branch ‘branch’
git checkout
create and switch to a branch ‘new-branch’
git checkout -b
1 |
|
merge branch ‘other-branch’ to current branch
git merge
1 |
|
push the current staging area to a stack
git stash
list the stack
git stash list
pop the top of stack
git stash pop
get the ‘num’th item in the stack and remove it from the stack
git stash pop stash@{
1 |
|
set a simple tag ‘tag-name’
git tag
set a annotated tag ‘tag-name’
git tag -a
show all tags
git tag
delete a tag
git tag -d
1 |
|
add a remote repository, and set its name ‘remote-repo’
git remote add
remove a remote repository ‘remote-repo’
git remote rm
show remote repositories
git remote
show detailed information of remote repositories
git remote -v
rename a remote name
git remote rename
set local branch ‘local-branch’ track remote branch ‘remote-branch’
git checkout
create a new local branch and track remote branch ‘remote-branch’
git checkout -b
1 |
|
push local repository branch ‘local-branch’ to remote repository ‘remote-repo’ branch ‘remote-branch’
git push
if the local branch and remote branch are of the same name ‘branch-name’
git push
delete a remote branch ‘remote-branch’
git push
1 |
|
fetch content of ‘remote’ and merge it with current branch
git pull
[progit-chinese]: http://git-scm.com/book/zh/
[progit-english]: http://git-scm.com/book