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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:56:06  来源:igfitidea点击:

Merge and delete branch in one step/command

gitmergegit-branchbranching-and-merging

提问by BendEg

Is it possible, to mergea branch and automatically deleteit 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:

编辑:

-dwill only remove merged branches while -Dwill also remove unmerged branches, so -dwill 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 mastercan be replaced by your current branch name.

这里的分支名称master可以替换为您当前的分支名称。

Don't forget the &&. If the first line fails then the second is not executed.

不要忘记&&. 如果第一行失败,则不执行第二行。