Merge pull request #895 from vanpipy/feature/optional-start-point-when-creeate-branch

feat(#861): add optional parameter --from to set the start point
This commit is contained in:
罗泽轩 2020-11-21 11:25:08 +08:00 committed by GitHub
commit 444722cf38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 15 deletions

View file

@ -20,6 +20,12 @@ do
REMOTE=origin
fi
;;
--from)
if [[ -n $2 ]]; then
START_POINT=$2
shift
fi
;;
*)
BRANCH=$1
esac
@ -44,9 +50,15 @@ then
rm -f "$stderr"
if [ $REMOTE_EXIT -eq 0 ]
then
git push $REMOTE HEAD:refs/heads/$BRANCH
git fetch $REMOTE
git checkout --track -b $BRANCH $REMOTE/$BRANCH
if [[ -n $START_POINT ]]; then
git fetch $REMOTE
git checkout --track -b $BRANCH $START_POINT
git push $REMOTE HEAD:refs/heads/$BRANCH
else
git push $REMOTE HEAD:refs/heads/$BRANCH
git fetch $REMOTE
git checkout --track -b $BRANCH $REMOTE/$BRANCH
fi
exit $?
else
echo
@ -56,4 +68,9 @@ then
fi
fi
git checkout -b $BRANCH
if [[ -n $START_POINT ]]
then
git checkout -b $BRANCH $START_POINT
else
git checkout -b $BRANCH
fi

View file

@ -32,6 +32,10 @@ do
--squash )
merge_mode="--squash"
;;
--from )
start_point=$2
shift
;;
* )
argv+=($1)
;;
@ -55,10 +59,24 @@ else
else
branch="$branch_prefix"/"${argv[0]}"
fi
if [[ -n $remote ]]
if [[ -n $remote ]] && [[ -z $start_point ]]
then
git create-branch -r $remote $branch
else
fi
if [[ -z $remote ]] && [[ -z $start_point ]]
then
git create-branch $branch
fi
if [[ -n $remote ]] && [[ -n $start_point ]]
then
git create-branch -r $remote --from $start_point $branch
fi
if [[ -z $remote ]] && [[ -n $start_point ]]
then
git create-branch --from $start_point $branch
fi
fi

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-CREATE\-BRANCH" "1" "June 2019" "" "Git Extras"
.TH "GIT\-CREATE\-BRANCH" "1" "November 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-create\-branch\fR \- Create branches
@ -19,6 +19,12 @@ Creates local branch named <branchname> and optionally sets up a remote tracking
Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\.
.
.P
<\-\-from [start_point]>
.
.P
Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\.
.
.P
<branchname>
.
.P

View file

@ -90,6 +90,10 @@
<p>Setup a remote tracking branch using <code>remote_name</code>. If <code>remote_name</code> is not supplied, use <code>origin</code> by default.</p>
<p>&lt;--from [start_point]&gt;</p>
<p>Setup a start point when the branch created. If <code>--from</code> is not supplied, use the current branch by default.</p>
<p>&lt;branchname&gt;</p>
<p>The name of the branch to create.</p>
@ -141,8 +145,8 @@ $ git create-branch -r upstream integration
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Jonhnny Weslley &lt;<a href="&#109;&#97;&#105;&#108;&#x74;&#x6f;&#58;&#x6a;&#119;&#64;&#x6a;&#x6f;&#x6e;&#x68;&#110;&#x6e;&#x79;&#119;&#x65;&#x73;&#x6c;&#x6c;&#101;&#121;&#46;&#x6e;&#101;&#116;" data-bare-link="true">&#106;&#x77;&#x40;&#106;&#111;&#x6e;&#104;&#x6e;&#x6e;&#x79;&#x77;&#x65;&#x73;&#108;&#108;&#101;&#x79;&#x2e;&#110;&#101;&#x74;</a>&gt;
Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#111;&#58;&#x6d;&#97;&#114;&#x6b;&#46;&#x70;&#x69;&#116;&#x6d;&#97;&#x6e;&#64;&#x67;&#109;&#x61;&#105;&#108;&#46;&#99;&#x6f;&#x6d;" data-bare-link="true">&#109;&#97;&#114;&#x6b;&#46;&#112;&#x69;&#116;&#x6d;&#x61;&#x6e;&#x40;&#103;&#x6d;&#x61;&#x69;&#108;&#x2e;&#99;&#111;&#x6d;</a>&gt;, Brian Murrell &lt;<a href="&#109;&#x61;&#x69;&#108;&#x74;&#111;&#58;&#98;&#x74;&#x6d;&#117;&#x72;&#x72;&#101;&#x6c;&#x6c;&#x40;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#98;&#x74;&#x6d;&#x75;&#114;&#x72;&#101;&#x6c;&#x6c;&#64;&#x67;&#x6d;&#97;&#x69;&#108;&#46;&#99;&#x6f;&#109;</a>&gt;.</p>
<p>Written by Jonhnny Weslley &lt;<a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#x6f;&#x3a;&#x6a;&#x77;&#64;&#106;&#x6f;&#x6e;&#x68;&#x6e;&#110;&#121;&#x77;&#101;&#115;&#108;&#x6c;&#x65;&#121;&#x2e;&#110;&#x65;&#x74;" data-bare-link="true">&#106;&#x77;&#x40;&#106;&#111;&#x6e;&#x68;&#110;&#110;&#x79;&#x77;&#101;&#x73;&#x6c;&#x6c;&#101;&#x79;&#x2e;&#110;&#x65;&#116;</a>&gt;
Modified by Mark Pitman &lt;<a href="&#109;&#x61;&#x69;&#108;&#116;&#x6f;&#x3a;&#109;&#x61;&#x72;&#x6b;&#46;&#112;&#x69;&#116;&#x6d;&#97;&#110;&#x40;&#x67;&#109;&#x61;&#105;&#x6c;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#109;&#x61;&#114;&#x6b;&#46;&#x70;&#x69;&#116;&#x6d;&#97;&#x6e;&#64;&#x67;&#109;&#97;&#x69;&#x6c;&#46;&#99;&#x6f;&#109;</a>&gt;, Brian Murrell &lt;<a href="&#109;&#x61;&#105;&#x6c;&#x74;&#111;&#58;&#98;&#116;&#109;&#117;&#114;&#x72;&#x65;&#108;&#108;&#64;&#x67;&#x6d;&#x61;&#105;&#x6c;&#46;&#99;&#x6f;&#109;" data-bare-link="true">&#x62;&#x74;&#109;&#117;&#114;&#114;&#x65;&#108;&#108;&#x40;&#103;&#109;&#x61;&#x69;&#x6c;&#x2e;&#x63;&#111;&#x6d;</a>&gt;.</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -155,7 +159,7 @@ Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#111;&#58;&#x
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>June 2019</li>
<li class='tc'>November 2020</li>
<li class='tr'>git-create-branch(1)</li>
</ol>

View file

@ -15,6 +15,10 @@ Creates local branch named &lt;branchname&gt; and optionally sets up a remote tr
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
&lt;--from [start_point]&gt;
Setup a start point when the branch created. If `--from` is not supplied, use the current branch by default.
&lt;branchname&gt;
The name of the branch to create.

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-FEATURE" "1" "April 2020" "" "Git Extras"
.TH "GIT\-FEATURE" "1" "November 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-feature\fR \- Create/Merge feature branch
@ -28,6 +28,12 @@ use \fBbranch_prefix\fR instead of \fBfeature\fR
Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\.
.
.P
<\-\-from [start_point]>
.
.P
Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\.
.
.P
<finish>
.
.P

View file

@ -93,6 +93,10 @@
<p> Setup a remote tracking branch using <code>remote_name</code>. If <code>remote_name</code> is not supplied, use <code>origin</code> by default.</p>
<p> &lt;--from [start_point]&gt;</p>
<p> Setup a start point when the branch created. If <code>--from</code> is not supplied, use the current branch by default.</p>
<p> &lt;finish&gt;</p>
<p> Merge and delete the feature branch.</p>
@ -136,9 +140,9 @@ $ git features finish dependencies</p></dd>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Jesús Espino &lt;<a href="&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x6a;&#x65;&#115;&#112;&#105;&#x6e;&#111;&#103;&#64;&#x67;&#109;&#x61;&#105;&#108;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#x6a;&#101;&#x73;&#x70;&#x69;&#x6e;&#x6f;&#103;&#64;&#x67;&#109;&#x61;&#x69;&#108;&#46;&#x63;&#111;&#x6d;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#109;&#97;&#x69;&#108;&#x74;&#x6f;&#58;&#x6d;&#97;&#x72;&#x6b;&#46;&#x70;&#x69;&#116;&#x6d;&#97;&#x6e;&#64;&#x67;&#x6d;&#97;&#x69;&#108;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#109;&#97;&#x72;&#107;&#46;&#112;&#x69;&#x74;&#109;&#x61;&#110;&#64;&#103;&#x6d;&#97;&#105;&#108;&#46;&#x63;&#x6f;&#109;</a>&gt;<br />
Modified by Carlos Prado &lt;<a href="&#x6d;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a;&#99;&#x61;&#x72;&#108;&#x6f;&#115;&#46;&#x70;&#x72;&#x61;&#100;&#x6f;&#64;&#99;&#x70;&#x72;&#97;&#x64;&#x6f;&#103;&#x2e;&#99;&#x6f;&#x6d;" data-bare-link="true">&#x63;&#97;&#x72;&#x6c;&#x6f;&#115;&#x2e;&#x70;&#114;&#97;&#x64;&#x6f;&#x40;&#99;&#x70;&#114;&#x61;&#x64;&#x6f;&#103;&#46;&#99;&#x6f;&#109;</a>&gt;</p>
<p>Written by Jesús Espino &lt;<a href="&#109;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#x6a;&#x65;&#115;&#112;&#105;&#x6e;&#x6f;&#x67;&#64;&#x67;&#x6d;&#97;&#105;&#108;&#46;&#x63;&#x6f;&#109;" data-bare-link="true">&#106;&#101;&#115;&#112;&#105;&#x6e;&#111;&#x67;&#x40;&#103;&#x6d;&#x61;&#105;&#x6c;&#x2e;&#99;&#x6f;&#x6d;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#x74;&#x6f;&#58;&#x6d;&#97;&#114;&#x6b;&#x2e;&#x70;&#x69;&#x74;&#x6d;&#x61;&#x6e;&#64;&#103;&#x6d;&#97;&#105;&#108;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#x6d;&#97;&#x72;&#107;&#x2e;&#x70;&#105;&#116;&#x6d;&#97;&#110;&#x40;&#x67;&#x6d;&#97;&#105;&#108;&#x2e;&#x63;&#111;&#x6d;</a>&gt;<br />
Modified by Carlos Prado &lt;<a href="&#x6d;&#97;&#105;&#x6c;&#116;&#111;&#x3a;&#x63;&#97;&#x72;&#108;&#111;&#x73;&#46;&#x70;&#114;&#x61;&#100;&#x6f;&#x40;&#99;&#112;&#114;&#x61;&#100;&#111;&#x67;&#46;&#x63;&#x6f;&#x6d;" data-bare-link="true">&#x63;&#x61;&#x72;&#108;&#111;&#x73;&#x2e;&#x70;&#x72;&#x61;&#x64;&#111;&#64;&#x63;&#x70;&#114;&#97;&#x64;&#111;&#103;&#x2e;&#99;&#111;&#109;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -151,7 +155,7 @@ Modified by Carlos Prado &lt;<a href="&#x6d;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a;&
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>April 2020</li>
<li class='tc'>November 2020</li>
<li class='tr'>git-feature(1)</li>
</ol>

View file

@ -20,6 +20,10 @@ git-feature(1) -- Create/Merge feature branch
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
&lt;--from [start_point]&gt;
Setup a start point when the branch created. If `--from` is not supplied, use the current branch by default.
&lt;finish&gt;
Merge and delete the feature branch.