Merge pull request #739 from sleagon/master

feat: Add -s(--soft) for git sync
This commit is contained in:
罗泽轩 2019-01-16 12:19:03 +08:00 committed by GitHub
commit 44dc1b9dba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 11 deletions

View file

@ -7,10 +7,11 @@ function _usage()
Usage:
${command} [<remote> <branch>]
${command} -h | --help
${command} -s | --soft
Sync local branch with <remote>/<branch>.
When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default.
All changes and untracked files and directories will be removed.
All changes and untracked files and directories will be removed unless you add -s(--soft).
Examples:
Sync with upstream of local branch:
@ -18,6 +19,9 @@ Examples:
Sync with origin/master:
${command} origin master
Sync without cleaning untracked files:
${command} -s
EOS
}
@ -29,6 +33,9 @@ function main()
_usage
exit
;;
-s | --soft)
local soft="true"
;;
* )
if [ "${remote}" = "" ]; then
local remote="$1"
@ -65,7 +72,11 @@ function main()
read res
case "${res}" in
"Y" | "y" | "yes" | "Yes" | "YES" )
git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}" && git clean -d -f -x
if [ "${soft}" = "true" ]; then
git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}"
else
git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}" && git clean -d -f -x
fi
;;
* )
echo "Canceled."

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-SYNC" "1" "October 2017" "" "Git Extras"
.TH "GIT\-SYNC" "1" "January 2019" "" ""
.
.SH "NAME"
\fBgit\-sync\fR \- Sync local branch with remote branch
.
.SH "SYNOPSIS"
\fBgit sync\fR [ <remote> <branch> ]
\fBgit sync\fR [\-\-soft] [ <remote> <branch> ]
.
.SH "DESCRIPTION"
Sync local branch with <remote>/<branch>\.
@ -16,7 +16,13 @@ Sync local branch with <remote>/<branch>\.
When <remote> and <branch> are not specified on the command line, upstream of local branch will be used by default\.
.
.P
All changes and untracked files and directories will be removed\.
All changes and untracked files and directories will be removed unless you add \-s(\-\-soft)\.
.
.SH "OPTIONS"
\-\-soft or \-s
.
.P
Add this flag if you want to preserve untracked files\.
.
.SH "EXAMPLES"
Sync local branch with its upstream
@ -44,6 +50,19 @@ $ git sync origin master
.
.IP "" 0
.
.P
Sync without cleaning untracked files:
.
.IP "" 4
.
.nf
$ git sync \-s origin master
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Takuma Yamaguchi <\fIkumon0587@gmail\.com\fR>
.

View file

@ -56,6 +56,7 @@
<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>
@ -75,7 +76,7 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p> <code>git sync</code> [ &lt;remote&gt; &lt;branch&gt; ]</p>
<p> <code>git sync</code> [--soft] [ &lt;remote&gt; &lt;branch&gt; ]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -83,7 +84,13 @@
<p> When &lt;remote&gt; and &lt;branch&gt; are not specified on the command line, upstream of local branch will be used by default.</p>
<p> All changes and untracked files and directories will be removed.</p>
<p> All changes and untracked files and directories will be removed unless you add -s(--soft).</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p> --soft or -s</p>
<p> Add this flag if you want to preserve untracked files.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
@ -97,9 +104,14 @@
<pre><code>$ git sync origin master
</code></pre>
<p> Sync without cleaning untracked files:</p>
<pre><code>$ git sync -s origin master
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Takuma Yamaguchi &lt;<a href="&#x6d;&#97;&#x69;&#x6c;&#116;&#x6f;&#x3a;&#107;&#x75;&#109;&#x6f;&#x6e;&#x30;&#53;&#56;&#55;&#64;&#x67;&#x6d;&#97;&#105;&#108;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#107;&#117;&#109;&#x6f;&#110;&#48;&#x35;&#x38;&#x37;&#64;&#103;&#109;&#97;&#105;&#108;&#x2e;&#x63;&#111;&#x6d;</a>&gt;</p>
<p>Written by Takuma Yamaguchi &lt;<a href="&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#x3a;&#x6b;&#117;&#109;&#x6f;&#x6e;&#x30;&#53;&#56;&#x37;&#x40;&#x67;&#x6d;&#x61;&#x69;&#x6c;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#107;&#117;&#109;&#111;&#x6e;&#x30;&#x35;&#x38;&#x37;&#x40;&#x67;&#x6d;&#97;&#x69;&#x6c;&#x2e;&#x63;&#x6f;&#109;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -112,7 +124,7 @@
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>October 2017</li>
<li class='tc'>January 2019</li>
<li class='tr'>git-sync(1)</li>
</ol>

View file

@ -3,7 +3,7 @@ git-sync(1) -- Sync local branch with remote branch
## SYNOPSIS
`git sync` [ &lt;remote&gt; &lt;branch&gt; ]
`git sync` [--soft] [ &lt;remote&gt; &lt;branch&gt; ]
## DESCRIPTION
@ -11,7 +11,14 @@ git-sync(1) -- Sync local branch with remote branch
When &lt;remote&gt; and &lt;branch&gt; are not specified on the command line, upstream of local branch will be used by default.
All changes and untracked files and directories will be removed.
All changes and untracked files and directories will be removed unless you add -s(--soft).
## OPTIONS
--soft or -s
Add this flag if you want to preserve untracked files.
## EXAMPLES
@ -23,6 +30,10 @@ git-sync(1) -- Sync local branch with remote branch
$ git sync origin master
Sync without cleaning untracked files:
$ git sync -s origin master
## AUTHOR
Written by Takuma Yamaguchi &lt;<kumon0587@gmail.com>&gt;