Merge pull request #924 from allejo/feature/delete-squashed-branches

This commit is contained in:
罗泽轩 2021-05-27 20:13:41 +08:00 committed by GitHub
commit cd8fe4f6e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 260 additions and 0 deletions

View file

@ -16,6 +16,7 @@
- [`git create-branch`](#git-create-branch)
- [`git delete-branch`](#git-delete-branch)
- [`git delete-merged-branches`](#git-delete-merged-branches)
- [`git delete-squashed-branches`](#git-delete-squashed-branches)
- [`git delete-submodule`](#git-delete-submodule)
- [`git delete-tag`](#git-delete-tag)
- [`git delta`](#git-delta)
@ -849,6 +850,17 @@ Deleted feature/dashboard (was 923befa).
...
```
## git delete-squashed-branches
Deletes branches that have been "squashed-merged" into a specified branch; this branch will be checked out as a side-effect. If no branch is specified, then it will default to the current checked out branch.
```bash
$ (feature-branch) git delete-squashed-branches main
Deleted branch dependabot/bundler/kramdown-2.3.1 (was 1d3fb00).
Deleted branch dependabot/bundler/rexml-3.2.5 (was a7e4052).
$ (main) git ...
```
## git fresh-branch
Create empty local branch `name`:

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
targetBranch=$1
if [[ -z $targetBranch ]]; then
targetBranch=$(git rev-parse --abbrev-ref HEAD)
else
git checkout $targetBranch
fi
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do
mergeBase=$(git merge-base $targetBranch $branch)
if [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then
git branch -D $branch
fi
done

View file

@ -49,6 +49,10 @@ _git_delete_branch(){
__gitcomp "$(__git_heads)"
}
_git_delete_squashed_branches(){
__gitcomp "$(__git_heads)"
}
_git_delete_submodule(){
__gitcomp "$(git submodule status | awk '{print $2}')"
}

View file

@ -158,6 +158,11 @@ _git-delete-branch() {
':branch-name:__gitex_branch_names'
}
_git-delete-squashed-branches() {
_arguments \
':branch-name:__gitex_branch_names'
}
_git-delete-submodule() {
_arguments \
@ -347,6 +352,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
create-branch:'create branches' \
delete-branch:'delete branches' \
delete-merged-branches:'delete merged branches' \
delete-squashed-branches:'delete squashed branches' \
delete-submodule:'delete submodules' \
delete-tag:'delete tags' \
delta:'lists changed files' \

View file

@ -17,6 +17,7 @@ set __fish_git_extras_commands \
"create-branch:Create branches" \
"delete-branch:Delete branches" \
"delete-merged-branches:Delete merged branches" \
"delete-squashed-branches:Delete squashed branches" \
"delete-submodule:Delete submodules" \
"delete-tag:Delete tags" \
"delta:Lists changed files" \
@ -106,6 +107,8 @@ complete -c git -f -n '__fish_git_using_command count' -l all -d 'detailed commi
complete -c git -x -n '__fish_git_using_command create-branch' -s r -l remote -a '(__fish_git_unique_remote_branches)' -d 'setup remote tracking branch'
# delete-branch
complete -c git -x -n '__fish_git_using_command delete-branch' -a '(__fish_git_branches)' -d 'branch to delete'
# delete-squashed-branches
complete -c git -x -n '__fish_git_using_command delete-squashed-branches' -a '(__fish_git_branches)' -d 'branch to target for squashed merges'
# delete-submodule
complete -c git -x -n "__fish_git_using_command delete-submodule" -a "(__fish_git submodule status 2>/dev/null | string trim | cut -d ' ' -f 2)" -d 'submodule to delete'
# delete-tag

View file

@ -0,0 +1,54 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "May 2021" "" "Git Extras"
.
.SH "NAME"
\fBgit\-delete\-squashed\-branches\fR \- Delete branches that were squashed
.
.SH "SYNOPSIS"
\fBgit\-delete\-squashed\-branches\fR [<branch\-name>]
.
.SH "DESCRIPTION"
Deletes all git branches that have been "squash\-merged" into \fBbranch\-name\fR\.
.
.SH "OPTIONS"
<branch\-name>
.
.P
The target branch were the "squashed\-merged" branches were committed to\. If no value is given, then the current checked out branch will be used\.
.
.SH "EXAMPLES"
Delete all branches that were "squash\-merged" into the current checked out branch\.
.
.IP "" 4
.
.nf
$ git delete\-squashed\-branches
.
.fi
.
.IP "" 0
.
.P
Delete all branches that were "squash\-merged" into the \fBmain\fR branch\. This will checkout the target branch and leave you on said branch after the command has completed\.
.
.IP "" 4
.
.nf
$ git delete\-squashed\-branches main
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Teddy Katz <\fIteddy\.katz@gmail\.com\fR> and Vladimir Jimenez <\fIme@allejo\.io\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>

View file

@ -0,0 +1,124 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<title>git-delete-squashed-branches(1) - Delete branches that were squashed</title>
<style type='text/css' media='all'>
/* style: man */
body#manpage {margin:0}
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
.mp h2 {margin:10px 0 0 0}
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
.mp h3 {margin:0 0 0 4ex}
.mp dt {margin:0;clear:left}
.mp dt.flush {float:left;width:8ex}
.mp dd {margin:0 0 0 9ex}
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
.mp pre {margin-bottom:20px}
.mp pre+h2,.mp pre+h3 {margin-top:22px}
.mp h2+pre,.mp h3+pre {margin-top:5px}
.mp img {display:block;margin:auto}
.mp h1.man-title {display:none}
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
.mp h2 {font-size:16px;line-height:1.25}
.mp h1 {font-size:20px;line-height:2}
.mp {text-align:justify;background:#fff}
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
.mp u {text-decoration:underline}
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
.mp b.man-ref {font-weight:normal;color:#434241}
.mp pre {padding:0 4ex}
.mp pre code {font-weight:normal;color:#434241}
.mp h2+pre,h3+pre {padding-left:0}
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
ol.man-decor {width:100%}
ol.man-decor li.tl {text-align:left}
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
ol.man-decor li.tr {text-align:right;float:right}
</style>
</head>
<!--
The following styles are deprecated and will be removed at some point:
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
.man-navigation should be used instead.
-->
<body id='manpage'>
<div class='mp' id='man'>
<div class='man-navigation' style='display:none'>
<a href="#NAME">NAME</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#AUTHOR">AUTHOR</a>
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
<a href="#SEE-ALSO">SEE ALSO</a>
</div>
<ol class='man-decor man-head man head'>
<li class='tl'>git-delete-squashed-branches(1)</li>
<li class='tc'>Git Extras</li>
<li class='tr'>git-delete-squashed-branches(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>git-delete-squashed-branches</code> - <span class="man-whatis">Delete branches that were squashed</span>
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-delete-squashed-branches</code> [&lt;branch-name&gt;]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p>Deletes all git branches that have been "squash-merged" into <code>branch-name</code>.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p> &lt;branch-name&gt;</p>
<p> The target branch were the "squashed-merged" branches were committed to. If no value is given, then the current checked out branch will be used.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p> Delete all branches that were "squash-merged" into the current checked out branch.</p>
<pre><code>$ git delete-squashed-branches
</code></pre>
<p> Delete all branches that were "squash-merged" into the <code>main</code> branch. This will checkout the target branch and leave you on said branch after the command has completed.</p>
<pre><code>$ git delete-squashed-branches main
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Teddy Katz &lt;<a href="&#109;&#97;&#x69;&#108;&#x74;&#x6f;&#58;&#116;&#x65;&#x64;&#x64;&#121;&#46;&#x6b;&#97;&#116;&#122;&#64;&#103;&#109;&#x61;&#105;&#108;&#46;&#99;&#x6f;&#x6d;" data-bare-link="true">&#x74;&#101;&#x64;&#100;&#x79;&#46;&#x6b;&#x61;&#x74;&#x7a;&#x40;&#x67;&#109;&#97;&#105;&#108;&#46;&#x63;&#111;&#109;</a>&gt; and Vladimir Jimenez &lt;<a href="&#x6d;&#97;&#x69;&#108;&#116;&#x6f;&#58;&#109;&#x65;&#x40;&#97;&#108;&#x6c;&#x65;&#x6a;&#111;&#x2e;&#105;&#x6f;" data-bare-link="true">&#109;&#x65;&#64;&#x61;&#x6c;&#108;&#x65;&#106;&#x6f;&#46;&#105;&#x6f;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
<p>&lt;<a href="https://github.com/tj/git-extras/issues" data-bare-link="true">https://github.com/tj/git-extras/issues</a>&gt;</p>
<h2 id="SEE-ALSO">SEE ALSO</h2>
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>May 2021</li>
<li class='tr'>git-delete-squashed-branches(1)</li>
</ol>
</div>
</body>
</html>

View file

@ -0,0 +1,38 @@
git-delete-squashed-branches(1) -- Delete branches that were squashed
=====================================================================
## SYNOPSIS
`git-delete-squashed-branches` [&lt;branch-name&gt;]
## DESCRIPTION
Deletes all git branches that have been "squash-merged" into `branch-name`.
## OPTIONS
&lt;branch-name&gt;
The target branch were the "squashed-merged" branches were committed to. If no value is given, then the current checked out branch will be used.
## EXAMPLES
Delete all branches that were "squash-merged" into the current checked out branch.
$ git delete-squashed-branches
Delete all branches that were "squash-merged" into the `main` branch. This will checkout the target branch and leave you on said branch after the command has completed.
$ git delete-squashed-branches main
## AUTHOR
Written by Teddy Katz &lt;<teddy.katz@gmail.com>&gt; and Vladimir Jimenez &lt;<me@allejo.io>&gt;
## REPORTING BUGS
&lt;<https://github.com/tj/git-extras/issues>&gt;
## SEE ALSO
&lt;<https://github.com/tj/git-extras>&gt;

View file

@ -44,6 +44,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-create-branch(1)** Create branches
- **git-delete-branch(1)** Delete branches
- **git-delete-merged-branches(1)** Delete merged branches
- **git-delete-squashed-branches(1)** Delete branches that were squashed
- **git-delete-submodule(1)** Delete submodules
- **git-delete-tag(1)** Delete tags
- **git-delta(1)** Lists changed files

View file

@ -16,6 +16,7 @@ git-cp(1) git-cp
git-create-branch(1) git-create-branch
git-delete-branch(1) git-delete-branch
git-delete-merged-branches(1) git-delete-merged-branches
git-delete-squashed-branches(1) git-delete-squashed-branches
git-delete-submodule(1) git-delete-submodule
git-delete-tag(1) git-delete-tag
git-delta(1) git-delta