git 一步/命令合并和删除分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35507239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge and delete branch in one step/command
提问by BendEg
Is it possible, to merge
a branch and automatically delete
it with a single command? The delete step should only be executed if merging was successful.
是否有可能,merge
一个分支并自动delete
使用单个命令?仅当合并成功时才应执行删除步骤。
回答by Zbynek Vyskovsky - kvr000
No, git doesn't support this at the same time.
不,git 不同时支持这个。
However, you can run the commands in a shell conditionally:
但是,您可以有条件地在 shell 中运行命令:
git merge source-branch && git branch -d source-branch
Edit:
编辑:
-d
will only remove merged branches while -D
will also remove unmerged branches, so -d
will ensure that the branch is merged and you don't delete a branch by accident.
-d
只会删除合并的分支,同时-D
也会删除未合并的分支,因此-d
将确保分支被合并并且您不会意外删除分支。
回答by ramwin
I will write a script.
我会写一个脚本。
git branch | grep -v master | xargs git merge &&
git branch | grep -v master | xargs git branch -d
Here the branch name master
can be replaced by your current branch name.
这里的分支名称master
可以替换为您当前的分支名称。
Don't forget the &&
. If the first line fails then the second is not executed.
不要忘记&&
. 如果第一行失败,则不执行第二行。