commit 为 git 的操作单元。
// init at local
git init
// clone from remote (protocal: ftp / ssh)
git clone
git branch
git branch new-branch
git branch -h
git add .
git commit -m -a ‘message’
merge 和 rebase 是两种不同的合并方式。merge 的log是有分叉的,合并后的commit的父亲是合并的多个分支的commit。rebase 则是将修改移动到最后,将log合并为一条。
merge 的缺点是 log 可能很乱。rebase的缺点是丢失了拉出,合并入分支的时间节点。
merge
rebase
拓展: fast forward => Instead of re-creating the commits in css and adding them to the history of master, Git reuses the existing snapshots and simply moves the tip of master to match the tip of css. This kind of merge is called a fast-forward merge, since Git is “fast-forwarding” through the new commits in the css branch.
拓展: merge 和 rebase 对 hash 的影响 => 不是 fast forward 模式,则会穿件新的 snapshot
命令
git add
单文件
git checkout filename
版本回退
git reset hash
回退单个 commit (创建个revert修改)
git revert hash
作为一个DCVS,git的远程 Repository 和本地是一样的。所以将 Repository 间操作单独拿出来。
fetch
Download objects and refs from another repository
// usage: git fetch [<options>] [<repository> [<refspec>...]]
// eg.
git fetch origin master:master
pull = fetch + merge (rebase)
Fetch from and integrate with another repository or a local branch
Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
// git pull [-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff] [--[no-]rebase|--rebase=preserve] [-s strategy]... [<fetch-options>] <repo> <head>...
// eg.
git pull origin master
push
Update remote refs along with associated objects
// usage: git push [<options>] [<repository> [<refspec>...]]
// eg.
git push origin master:master
clone
Clone a repository into a new directory
在deploy根据项目创建分支
git fetch dev-source remote-project-pmt-x:local-project-pmt-x
开发 ……
git add ……
git commit ……
开发完成,推送到 dev-source 等待测试
git push dev-souce local-project-pmt-x:remote-project-pmt-x
测试完毕,rebase production-source mater,如果有冲突,解决冲突
git fetch production-source mater
git rebase FETCH
rebase 结束,push 到 dev-source 等待合并
得到最新的branch分支,并rebase最新的master
git fetch dev-source remote-project-pmt-x:local-project-pmt-x
git checkout master
git pull —rebase
git checkout local-project-pmt-x
git rebase master
checkout 到 master,merge rebase
git checkout master
git merge —no-ff local-project-pmt-x
production master 线只作 merge 操作,但是它的目标branch都是先 rebase 过master的,所以新的部分一定是单线的,merge的话最多只会有一条分支。如此就是的log如rebase一般清晰的同时,也适当保留了“每个版本”的拉出和回来的点。
这是种针对公司发布版本的优化,并没法像是原生的mergelog那么详细。
====================================================
git document: http://git-scm.com/doc
Git for Computer Scientists: http://eagain.net/articles/git-for-computer-scientists/
Ry’s Git Tutorial: http://rypress.com/tutorials/git/