快捷说明
git stash
- 暂存当前工作git stash list
- 查看暂存工作列表git stash pop
- 回到暂存工作git branch branch_name
- 创建分支(以当前分支为基础)git pull
- 更新当前分支git branch -D branch_name
- 删除本地分支git push origin :branch_name
- 删除远程分支git push --delete origin branch_name
- 删除远程分支git push origin branch_name
- 推送本地分支到远程git merge branch_name
- 把指定分支合并到当前分支git clean -d -fx
- 清理GIT命令git reset --hard branch_name
- 重置本地分支git reset --hard origin branch_name
- 重置远程分支git log
- 查看日志历史git rebase -i HEAD~[0]
- 合并当前分支多个历史提交
常用小技巧
批量删除远程分支
1
git branch -r | grep 'filter_name' | awk -F '/' '{print $2}' | xargs git push --delete origin
彻底删除历史记录(由于历史存在大文件)
1
git filter-branch -f --tree-filter 'rm -rf build/*' HEAD
合并时忽略某些文件
在合并的时候我们想
master
分支保留某些文件不被子分支改变的话可以采用.gitattributes
来进行定义合并策略过滤项,最后利用git config
进行最终合并策略的设置,git config
分为全局与项目范围设置,这个不深入展开。创建
.gitattributes
文件在项目根目录, 过滤文件在某个合并策略下:1
src/test/resources/testng.xml merge=ours
设置项目范围的策略配置:
1
git config merge.ours.driver true
仓库迁移(包含所有的
branches
与tags
)1 2 3 4
git clone --mirror git@github.com:caryyu/sample cd sample.git git remote set-url --push origin git@gitlab.caryyu.top:caryyu/sample.git git push --mirror
Git 代理设置
如果
clone
用的普通 HTTPS 方式,则只需要用下列简单的方法就可以了:1
export https_proxy=http://127.0.0.1:7890
但是,如果使用的 SSH 方式 clone 的,则需要用一个额外的程序辅助:
安装下载 socat 到 MacOS:
1
brew install socat
配置
~/.ssh/config
文件:1 2 3
Host github.com IdentityFile ~/.ssh/id_rsa proxycommand socat - PROXY:127.0.0.1:%h:%p,proxyport=7890