git 常用脚本

/ 教程 / 没有评论 / 476浏览

一键清理本地分支:删除除master之外的本地分支,同步远程分支

执行前一定要提交当前分支的更改哦

git checkout master;git branch | xargs git branch \-d;git remote prune origin;

合并Commits

将多个提交记录进行合并

git rebase -i ${commitId}

commitId是最近一条不需要合并的commit的id

pick 2dfbc7e1 commit1
pick 2dfbc7e2 commit2
pick 2dfbc7e3 commit3

修改为

pick 2dfbc7e1 commit1
s 2dfbc7e2 commit2
s 2dfbc7e3 commit3

s 表示要合并的commit

#the first commit
commit1
#the second commit
commit2
#the third commit
commit3

改为

#the first commit
merge commits
- commit1
- commit2
- commit3

最重要的一步:强制提交

git push --force

完成

生成

#全局配置
git config --global user.name "Clive Yuan"
git config --global user.email "xxxx@foxmail.com"
cd ~/.ssh    
mkdir ~/.ssh
ssh-keygen -t rsa -C "clive@xxx.com"
cat ~/.ssh/id_rsa.pub
ssh -T git@gitee.com

别名

up = pull --rebase --autostash
acp = "!f() { git add -A && git commit -m "$@" && git push; }; f"
ac = "!f() { git add -A && git commit -m "$@"; }; f"
cleanbranch = "checkout master;branch | xargs branch \\-d;remote prune origin;"

# 忽略换行符

git config core.autocrlf false