git 使用常见问题

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 "$@"'

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fighting Horse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值