Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理 git 分支总结 #57

Open
liyatang opened this issue Dec 20, 2018 · 0 comments
Open

整理 git 分支总结 #57

liyatang opened this issue Dec 20, 2018 · 0 comments

Comments

@liyatang
Copy link
Contributor

liyatang commented Dec 20, 2018

这次整理 git 分支学到的几个命令

git branch 查看分支情况

git branch -r 查看远程分支情况

git branch -r --merged 查看已经merged的分支

git branch -D 删除分支

git push origin --delete xxxx 删除远程分支

git branch -r --sort=-committerdate 按最近提交倒序排

git remote prune origin 远程分支没了,但是本地还有,可以用此命令

grep -v 排除

sed 's/origin\///g' 字符串替换 origin 为 空,其中 s 代表替换

> ~/branch.txt 输出到文件

xargs 将标准输入数据转换成命令行

实际使用

删除本地分支,

// 排除 master 和 feature-dev
git branch | grep -v master | grep -v feature-dev | xargs git branch -D

删除远程分支

// 先按最近提交倒序排,并输入到文件
git brnach -r --sort=committerdate > ~/branch.txt

// 保险起见,人工做二次检查
open ~/branch.txt

// 把分支开头的 origin/ 替换成空字符串,然后输出给 xargs ,进而删除分支操作
cat ~/branch.txt | sed 's/origin\///g' | xargs git push origin --delete

远程分支改了,同步到本地

git fetch -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant