Git Gotchas
本文是在实践中使用Git,遇到问题,然后解决问题的过程!
###Why Git?
这个问题我无法回答,我没有使用过SVN等等工具,一开始接触就是Git, 不过发现自从使用它之后,就深深的爱上她了!
###SSH
不管是使用Github,还是git@osc, 如果你想安心在上面写点东西,那么SSH是必需的!
Tips
-
在自己家目录里新建一个文件夹.ssh
-
使用
ssh-keygen命令时加上-F hostname和-C comment参数-
-F hostname: 查找hostname,如果这个host上已经有ssh密钥了,就不用在生成添加了。当然你也可以再次生成添加 -
-C comment: 注释,会出现在SSH公钥文件里 -
Enter file in which to save the key (/home/lee/.ssh/id_rsa):: 输入_见名之意_的文件名,方便管理
-
###Git General Operation
查看更多:
注意几点:
-
git commit -m comment必须要有-m comment,不然就提交不上。建议注释使用 #001 fixed .... 这样更形象。 -
如果远程库和本地库不一样,请先pull之后再push。
-
git merge --no-ff otherBranch: 参数--no-ff很有用。 -
git push origin :otherBranch: 会删除远程的otherBranch分支
当然,建议一点:有意识的使用标签:
git tag: 显示已有标签
git tag v0.1.1 commit_hash_code: 给commit_hash_code这次条件打上标签,方便人查看管理,当然也可以加上-a,-m,-s参数更完美。
git push --tags: 将本地的标签push到远程上去
git tag -d v0.1.1: 删除本地上这个标签
git push origin :refs/tags/v0.1.1:删除远程origin上的这个标签
有关gist使用图片问题,请查看我的上一篇博文在github gist上添加图片
###Git flow 如果你是团队开发或者想让自己看起来更专业,那么你可以试试Git flow.

安装: git flow
查看更多:
###bashrc setting 如果你使用的是Linux系统,发福利了,在终端下显示git当前分支和状态!
# ============== begin git setting======== # Ubuntu 中 Terminal 下 Bash 提示中显示 git 当前分支和状态 # username@hostname:directory[branch-name]$ # 干净的工作目录 # username@hostname:directory[branch-name*]$ # 不干净的工作目录 function parse_git_dirty { [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" } export PS1='\u@\h:\W\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ ' # ===========end git setting========== # ===========end of configuration=====

###Example 鄙人写了一个python Nose模块的一个插件colorunit,如果你方便的话,请帮忙测试一下windows或者其它平台下的运行(PS:鄙人只有Ubuntu系统), 或者加入一起完善