1 git 配置
1.1 设置文本编辑器
git config --global core.editor vim
git config --global diff.tool vimdiff
git config --global merge.tool vimdiff
1.2 设置默认配置
git config --global pull.rebase true
git config --global push.default simple
git config --global core.autocrlf input
git config --global core.quotepath false
1.3 设置命令简写
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.di diff
git config --global alias.sw show
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
1.4 设置项目配置
git config core.fileMode false
2 git 使用
2.1 使用 vimdiff 编辑修改
git difftool
以只读方式打开,需要在 vim 中 :set noro,才能修改
3 git 高级
2.1 打包
git archive --format=tar --prefix=git-1.4.0 v1.4.0 | gzip > git-1.4.0.tar.gz
2.2 批量修改提交信息
修改提交作者,从"aaa"替换为:bbb":
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "aaa" ]; then GIT_AUTHOR_NAME=bbb; fi; git commit-tree $@;'
修改提交说明,替换所有“abc”为“def”:
git filter-branch --msg-filter "sed 's/abc/def/g' /dev/stdin"
文件名称修改,目录 xxx 重命名为 yyy
git filter-branch --tree-filter 'git mv -f src/com/xxx src/com/yyy' HEAD
修改文件内容,xxx 修改 为 yyy
git filter-branch --tree-filter 'find . -name \*.xml -exec sed -i "s|com.xxx|com.yyy|g" {} \;'
2 git svn
2.1 统一 email 账号
echo "#\!/bin/bash" > author.sh
echo "echo \$1 \<\$1@pptv.com\>" >> author.sh
chmod +x author.sh
2.2 带分支 clone
git svn init -T trunk -b branches -t tags http://svn01/repositories/r01/base base
cd base
git svn fetch --authors-prog=../author.sh
cd ..
2.3 过滤某些目录
git svn init --ignore-paths "(?:trunk|branches|tags)" http://svn01/repositories/r01/base build
cd build
git svn fetch --authors-prog=../author.sh
cd ..
2.4 删除空的提交
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"'