简体   繁体   English

在git中删除上一个分支的快捷方式

[英]Shortcut for deleting previous branch in git

In git it would be helpful to be able to easily delete the previous branch I was on. 在git中,能够轻松删除我以前所在的分支将很有帮助。 You can't delete the branch you're on so you need to check out a new/existing branch and delete the previous you where on by writing it's full name. 您无法删除所在的分支,因此需要签出新的/现有的分支,并通过写下其全名来删除先前的分支。

git checkout new_branch
git branch -D old_branch_with_really_long_and_hard_name

What I really want is to be able to do this: 我真正想要的是能够做到这一点:

git checkout new_branch
git branch -D -

- doesn't work, but - is just an alias for @{-1} and that does work. -不起作用,但是-只是@{-1}的别名,它确实起作用。 So you workflow would be this: 所以您的工作流程将是这样的:

git checkout new_branch
git branch -D @{-1}

Amendment: 修正案:

Turning this into the git alias git done : 把它变成git别名git done

git config --global alias.done '!f() { git checkout master && git branch -D @{-1}; }; f'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM