{
    "componentChunkName": "component---src-templates-blog-post-jsx",
    "path": "/post/should-use-delete-option-to-delete-git-branch-or-tag/",
    "result": {"data":{"site":{"siteMetadata":{"title":"WEB EGG","author":"Leko - CTO at Yuimedi"}},"markdownRemark":{"id":"cd504423-19ef-519e-9f84-ebe56c6128cc","excerpt":"この記事は12/19 の Git Advent Calendarの記事です。 ひょんなことから、リモートの Git サーバにある 4000 個のタグを一括削除することになりました。 タグ消すときはgit push origin :タグ名でタグを消してたのですが、 400…","html":"<p>この記事は<a href=\"http://qiita.com/advent-calendar/2016/git\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">12/19 の Git Advent Calendar</a>の記事です。</p>\n<p>ひょんなことから、リモートの Git サーバにある 4000 個のタグを一括削除することになりました。</p>\n<p>タグ消すときは<code>git push origin :タグ名</code>でタグを消してたのですが、 4000 個もあると丸一日待っても終わらないので、他に素早く消せる方法はないだろうか、 とコマンドを探していたら良いものを見つけた、という備忘録です。</p>\n<p>※タグについて書きますがブランチにおいても同様です。</p>\n<!--more-->\n<h2 id=\"git-push-origin-タグ名\" style=\"position:relative;\"><a href=\"#git-push-origin-%E3%82%BF%E3%82%B0%E5%90%8D\" aria-label=\"git push origin タグ名 permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Git push origin :タグ名</h2>\n<p>:は区切り文字に相当しており、おそらく普段使っているように省略すると</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git push origin master # 省略前\ngit push origin master:master # 省略後</code></pre></div>\n<p>のように扱われています。 これを応用すればローカルとリモートで異なるブランチ名に push できるのですが、そんなことする得が無いので基本省略すると思います。</p>\n<blockquote>\n<p><code>:&#x3C;dst></code> part can be omitted—​such a push will update a ref that <code>&#x3C;src></code> normally updates without any <code>&#x3C;refspec></code> on the command line. Otherwise, missing <code>:&#x3C;dst></code> means to update the same ref as the <code>&#x3C;src></code>.<br>\n— <a href=\"https://git-scm.com/docs/git-push\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Git – git-push Documentation</a></p>\n</blockquote>\n<p>で、<code>:</code>を付けて左側に何も書かないと、「無と push する」みたいな動作になります。 これに関しては、どこぞの TAS 動画で「無を掴む」とか表現されたりするように、概念的に理解しようとするより、結果論で覚えたほうが早いと思います。</p>\n<blockquote>\n<p>Pushing an empty <code>&#x3C;src></code> allows you to delete the <code>&#x3C;dst></code> ref from the remote repository.<br>\n— <a href=\"https://git-scm.com/docs/git-push\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Git – git-push Documentation</a></p>\n</blockquote>\n<h2 id=\"git-push-origin-delete-タグ名\" style=\"position:relative;\"><a href=\"#git-push-origin-delete-%E3%82%BF%E3%82%B0%E5%90%8D\" aria-label=\"git push origin delete タグ名 permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Git push origin –delete タグ名</h2>\n<p><code>git push --delete origin hogehoge</code> のようなコマンドを叩くとリモートブランチが削除されます。</p>\n<blockquote>\n<p>–delete > All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon.<br>\n— <a href=\"https://git-scm.com/docs/git-push\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Git – git-push Documentation</a></p>\n</blockquote>\n<p>ただ、どうにも遅い。なんとかできないか調べてました。</p>\n<h2 id=\"push-時に複数ブランチタグが指定できる\" style=\"position:relative;\"><a href=\"#push-%E6%99%82%E3%81%AB%E8%A4%87%E6%95%B0%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E3%82%BF%E3%82%B0%E3%81%8C%E6%8C%87%E5%AE%9A%E3%81%A7%E3%81%8D%E3%82%8B\" aria-label=\"push 時に複数ブランチタグが指定できる permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>push 時に複数ブランチ・タグが指定できる</h2>\n<p>Git-push は複数のブランチを一気に push できます。試したことがなかった。</p>\n<p><code>git push origin :hoge :foo :bar</code>のようにやれば、複数のブランチ・タグを一括削除できます。 もしくは<code>--delete</code>オプションをつけても内部挙動としては同じです。 １個ずつ指定していく場合と比べてめちゃくちゃ早いです。</p>\n<h2 id=\"どれくらい違うのか\" style=\"position:relative;\"><a href=\"#%E3%81%A9%E3%82%8C%E3%81%8F%E3%82%89%E3%81%84%E9%81%95%E3%81%86%E3%81%AE%E3%81%8B\" aria-label=\"どれくらい違うのか permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>どれくらい違うのか</h2>\n<p>タグを 100 個切ってリモートにあげてから、それを全部削除するまでの時間を図ってみました。 ネットワーク状況の揺れを最小限にするよう有線で試しましたが、それでも誤差はあると思います。</p>\n<table>\n<thead>\n<tr>\n<th>方法</th>\n<th>時間</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>１個ずつ+<code>:</code></td>\n<td>8m40.951s</td>\n</tr>\n<tr>\n<td>１個ずつ+<code>--delete</code></td>\n<td>8m35.192s</td>\n</tr>\n<tr>\n<td>一括+<code>:</code></td>\n<td>0m14.854s</td>\n</tr>\n<tr>\n<td>一括+<code>--delete</code></td>\n<td>0m4.338s</td>\n</tr>\n</tbody>\n</table>\n<p>はい、結果は歴然です。 <strong>一括削除したほうが圧倒的に早いです</strong> 。</p>\n<h2 id=\"まとめ\" style=\"position:relative;\"><a href=\"#%E3%81%BE%E3%81%A8%E3%82%81\" aria-label=\"まとめ permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>まとめ</h2>\n<p>私は、破壊的な操作をショートハンドでやるのは怖い（1 文字オプションも見間違い・勘違いが怖いので使わない）と思っているので、 セーフティという意味では十分意図通りの挙動と安全性を提供してくれていると思います。</p>\n<p>ということで、これからはリモートにあるブランチやタグを一気にを消すときは<code>--delete</code>オプションを愛用すると思います。</p>","timeToRead":4,"frontmatter":{"title":"リモートのタグを一括削除するときは–deleteを使おうと思った話","tags":["Git"],"date":"December 21, 2016","featuredImage":null}}},"pageContext":{"slug":"/should-use-delete-option-to-delete-git-branch-or-tag/","previous":{"fields":{"slug":"/how-to-run-testcase-of-selenium-ide-in-cli/"},"frontmatter":{"title":"Selenium IDEで作ったテストをCLI環境で動かしてみる","tags":["CI","Selenium"]}},"next":{"fields":{"slug":"/nextengine-api-client-with-nodejs/"},"frontmatter":{"title":"ネクストエンジンAPIのNodejs版クライアント作った","tags":["Nodejs"]}}}},
    "staticQueryHashes": ["2585454260","2954598359"]}