{"id":4416,"date":"2021-07-14T19:47:27","date_gmt":"2021-07-14T10:47:27","guid":{"rendered":"https:\/\/www.chihayafuru.jp\/tech\/?p=4416"},"modified":"2021-07-15T09:54:05","modified_gmt":"2021-07-15T00:54:05","slug":"git-%e3%82%84%e3%82%8a%e7%9b%b4%e3%81%97%e7%b3%bb%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/4416","title":{"rendered":"[git] \u3084\u308a\u76f4\u3057\u7cfb\u30b3\u30de\u30f3\u30c9"},"content":{"rendered":"<p>\u300c\u3084\u308a\u76f4\u3057\u7cfb\u30b3\u30de\u30f3\u30c9\u300d\u306f\u79c1\u306e\u9020\u8a9e\u3067\u3059\u3002git\u306e\u64cd\u4f5c\u306f\u5e38\u306b\u3084\u308a\u76f4\u305b\u307e\u3059\u3002<br \/>\n\u300c\u6253\u3061\u6d88\u3059\u300d\u3001\u300c\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u300d\u3001\u300c\u524a\u9664\u3059\u308b\u300d\u3001\u300c\u30af\u30ea\u30fc\u30f3\u3059\u308b\u300d\u306a\u3069\u3001\u300c\u3084\u308a\u76f4\u3059\u300d\u305f\u3081\u306egit\u306e\u30b3\u30de\u30f3\u30c9\u3084\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<!--more--><\/p>\n<p>\u672c\u6295\u7a3f\u3067\u306f\u4e00\u3064\u4e00\u3064\u306e\u30b3\u30de\u30f3\u30c9\u3084\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u8a73\u7d30\u306b\u306f\u8e0f\u307f\u8fbc\u307f\u307e\u305b\u3093\u3002<br \/>\n<code>git rebase --abort<\/code> (\u30ea\u30d9\u30fc\u30b9\u306e\u7834\u68c4) \u3092\u8aac\u660e\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u30ea\u30d9\u30fc\u30b9\u3068\u306f\u4f55\u305e\u3084\u304b\u3089\u8aac\u660e\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u305f\u3081\u8aac\u660e\u306e\u4e00\u90e8\u3092\u7aef\u6298\u308a\u307e\u3059\u3002<\/p>\n<p>\u300c\u5909\u66f4\u3092\u7834\u68c4\u3059\u308b\u300d\u3068\u3044\u3046\u65e5\u672c\u8a9e\u5316\u3055\u308c\u305fGUI\u30e1\u30cb\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u4ee5\u4e0b\u306e\u3044\u305a\u308c\u306egit\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u304b\u78ba\u4fe1\u304c\u6301\u3066\u306a\u3044\u306e\u3067\u3042\u308c\u3070\u3001\u6016\u304f\u3066\u30dc\u30bf\u30f3\u3092\u9078\u629e\u3067\u304d\u307e\u305b\u3093\u3002 \u300c\u65e5\u672c\u8a9e\u5316\u3057\u305fgit\u30a2\u30d7\u30ea\u306f\u6016\u3044\u3067\u3059\u3088\uff01\u300d\u3001\u300cGUI\u306egit\u30a2\u30d7\u30ea\u306f\u4fbf\u5229\u306a\u3088\u3046\u3067\u30af\u30bb\u304c\u3042\u308a\u307e\u3059\u3088\uff01\u300d\u3068\u3044\u3046\u3053\u3068\u3092\u5553\u8499\u3059\u308b\u305f\u3081\u306e\u30dd\u30a8\u30e0\u3067\u3059\u3002<\/p>\n<h3>1. revert (\u6253\u3061\u6d88\u3059)<\/h3>\n<h4>1.1. \u6700\u5f8c\u306e\u30b3\u30df\u30c3\u30c8\u3092\u6253\u3061\u6d88\u3059\u30b3\u30df\u30c3\u30c8\u3092\u8ffd\u52a0\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git revert HEAD<\/pre>\n<p>HEAD(\u2252\u30ab\u30ec\u30f3\u30c8\u30d6\u30e9\u30f3\u30c1\u306e\u672b\u7aef)\u306e\u30b3\u30df\u30c3\u30c8\u3092\u6253\u3061\u6d88\u3059\u30b3\u30df\u30c3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<h4>1.2. \u7279\u5b9a\u306e\u30b3\u30df\u30c3\u30c8\u3092\u6253\u3061\u6d88\u3059\u30b3\u30df\u30c3\u30c8\u3092\u8ffd\u52a0\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git revert 286dc77<\/pre>\n<p>\u30b3\u30df\u30c3\u30c8 286dc77 \u3092\u6253\u3061\u6d88\u3059\u30b3\u30df\u30c3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n\u203b \u3044\u3064\u3001\u8ab0\u304c\u3001\u3069\u3046\u3044\u3046\u5909\u66f4\u3092\u3057\u305f\uff06\u5909\u66f4\u3092\u6253\u3061\u6d88\u3057\u305f(revert\u3057\u305f)\u304b\u30ad\u30c1\u30f3\u3068\u5909\u66f4\u5c65\u6b74\u306b\u6b8b\u308b\u884c\u5100\u306e\u826f\u3044\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h3>2. reset (\u30ea\u30bb\u30c3\u30c8\u3059\u308b)<\/h3>\n<h4>2.1. \u3072\u3068\u3064\u524d\u306e\u30b3\u30df\u30c3\u30c8\u306b\u30b3\u30df\u30c3\u30c8\u3060\u3051\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git reset HEAD^<\/pre>\n<p>\u6700\u5f8c\u306e\u30b3\u30df\u30c3\u30c8(HEAD)\u3092\u306a\u304b\u3063\u305f\u3053\u3068\u306b\u3059\u308b\u3002<br \/>\n\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u3068\u30ef\u30fc\u30af\u306f\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u524d\u5f8c\u3067\u5909\u5316\u3057\u307e\u305b\u3093\u3002\u30b3\u30df\u30c3\u30c8\u3092\u306a\u304b\u3063\u305f\u3053\u3068\u306b\u3059\u308b\u3060\u3051\u3067\u4fee\u6b63\u9014\u4e2d\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u624b\u5143\u306b\u6b8b\u308a\u307e\u3059\u3002<\/p>\n<h4>2.2. \u3072\u3068\u3064\u524d\u306e\u30b3\u30df\u30c3\u30c8\u306b\u5168\u3066\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git reset --hard HEAD^<\/pre>\n<p>\u6700\u5f8c\u306e\u30b3\u30df\u30c3\u30c8(HEAD)\u3092\u306a\u304b\u3063\u305f\u3053\u3068\u306b\u3059\u308b\u3002<br \/>\n\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u3068\u30ef\u30fc\u30af\u3082\u30ea\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002\u524d\u3005\u56de\u306e\u30b3\u30df\u30c3\u30c8\u4ee5\u964d\u306e\u5909\u66f4\u304c\u4e00\u5207\u5408\u5207\uff08\uff1d\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u304b\u3089\u3082\u30ef\u30fc\u30af\u304b\u3089\u3082\uff09\u6d88\u3048\u3066\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>2.3. reset\u306e\u6ce8\u610f\u70b9<\/h4>\n<p>reset\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u3068\u300c\u30b3\u30df\u30c3\u30c8\u3092\u306a\u304b\u3063\u305f\u3053\u3068\u300d\u306b\u3067\u304d\u307e\u3059\u3002\u3057\u304b\u3057\u30ea\u30e2\u30fc\u30c8\u30b5\u30fc\u30d0\u30fc\u306bpush\u3057\u305f\u3042\u3068\uff08\u5909\u66f4\u5c65\u6b74\u3092\u30e1\u30f3\u30d0\u30fc\u3068\u5171\u6709\u3057\u305f\u5f8c\uff09\u306b\u300c\u306a\u304b\u3063\u305f\u3053\u3068\u300d\u306b\u3059\u308b\u3068\u3001\u540c\u3058\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u5171\u6709\u3057\u3066\u3044\u308b\u4ed6\u306e\u30e1\u30f3\u30d0\u30fc\u306e\u65b0\u305f\u306a\u5909\u66f4\u3082\u306a\u304b\u3063\u305f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u300c\u306a\u304b\u3063\u305f\u3053\u3068\u300d\u306b\u3055\u308c\u305f\u30e1\u30f3\u30d0\u30fc\u306b\u8b1d\u7f6a\u3057\u3066\u6b69\u304f\u6c17\u304c\u306a\u3044\u306e\u3067\u3042\u308c\u3070\u3001push\u5f8c\u306ereset\u3084 force push \u306f\u63a7\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>3. restore (\u5fa9\u5143\u3059\u308b)<\/h3>\n<h4>3.1. \u30ef\u30fc\u30af\u3092\u5fa9\u5143\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git restore hello.c<\/pre>\n<p>\u30ef\u30fc\u30af\u306b\u5bfe\u3059\u308b\u5909\u66f4\u3092\u7834\u68c4\u3057\u3066\u3001\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u304b\u3089\u30ef\u30fc\u30af\u3078hello.c\u3092\u5fa9\u5143\u3059\u308b\u3002<\/p>\n<h4>3.2. \u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u3092\u5fa9\u5143\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git restore --staged hello.c<\/pre>\n<p>\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u306b\u5bfe\u3059\u308b\u5909\u66f4\u3092\u7834\u68c4\u3057\u3066\u3001\u30b3\u30df\u30c3\u30c8\u304b\u3089\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u3078hello.c\u3092\u5fa9\u5143\u3059\u308b\u3002<br \/>\n<code>git add hello.c<\/code> \u3084 <code>git rm hello.c<\/code> \u306a\u3069\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u306b\u5bfe\u3059\u308b\u64cd\u4f5c\u3092\u7834\u68c4\u3059\u308b\u3002<\/p>\n<h3>4. rm (\u524a\u9664\u3059\u308b)<\/h3>\n<h4>4.1. \u8ffd\u8de1\u5bfe\u8c61\u304b\u3089\u524a\u9664\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git rm hello.c<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb &#8220;hello.c&#8221; \u3092\u8ffd\u8de1\u5bfe\u8c61\uff08\uff1d\u4eca\u5f8c\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u306e\u5bfe\u8c61\uff09\u304b\u3089\u5916\u3059\u3002\u30d5\u30a1\u30a4\u30eb\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u3067hello.c\u3092\u524a\u9664\u3057\u305f\u3060\u3051\u3067\u306f\u6700\u65b0\u30b3\u30df\u30c3\u30c8\u306e\u4e2d\u306bhello.c\u304c\u6b8b\u308a\u7d9a\u3051\u308b\u3002\u3086\u3048\u306b rm \u30b3\u30de\u30f3\u30c9\u3067\u8ffd\u8de1\u5bfe\u8c61\u304b\u3089\u5916\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<h3>5. abort (\u4e2d\u6b62\u3059\u308b)<\/h3>\n<h4>5.1. \u30b3\u30f3\u30d5\u30ea\u30af\u30c8\u304c\u767a\u751f\u3057\u305f\u30de\u30fc\u30b8\u3092\u53d6\u308a\u6b62\u3081\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git merge --abort<\/pre>\n<h4>5.2. \u30b3\u30f3\u30d5\u30ea\u30af\u30c8\u304c\u767a\u751f\u3057\u305f\u30ea\u30d9\u30fc\u30b9\u3092\u53d6\u308a\u6b62\u3081\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git rebase --abort<\/pre>\n<h3>6. clean (\u6383\u9664\u3059\u308b)<\/h3>\n<h4>6.1. \u30ab\u30ec\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u30fc\u306e\u672a\u8ffd\u8de1\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30ef\u30fc\u30af\u304b\u3089\u524a\u9664\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git clean -f .<\/pre>\n<p>\u305f\u3068\u3048\u3070 *.bak \u306a\u3069\u306e\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u3092\u30ab\u30ec\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u4e00\u6c17\u306b\u524a\u9664\u3059\u308b\u3068\u304d\u306b\u4f7f\u3046\u3002<\/p>\n<h3>7. amend (\u4fee\u6b63\u3059\u308b)<\/h3>\n<h4>7.1. \u76f4\u524d\u306e\u30b3\u30df\u30c3\u30c8\u3092\u4fee\u6b63\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git commit --amend<\/pre>\n<p>\u76f4\u524d\u306e\u30b3\u30df\u30c3\u30c8\u3092\u306a\u304b\u3063\u305f\u3053\u3068\u306b\u3057\u3066\u3001\u65b0\u3057\u3044\u30b3\u30df\u30c3\u30c8\u3092\u4f5c\u308b\u4e00\u9023\u306e\u6d41\u308c\u3092\uff11\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b\u3002<\/p>\n<ol>\n<li>\u30b3\u30df\u30c3\u30c8\u3068\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u306e\u5dee\u7570\u304c\u306a\u3051\u308c\u3070\u3001\u30b3\u30df\u30c3\u30c8\u30b3\u30e1\u30f3\u30c8\u3092\u4fee\u6b63\u3059\u308b\u3060\u3051\u3002\u305f\u3060\u3057\u30b3\u30e1\u30f3\u30c8\u3092\u5909\u66f4\u3059\u308b\u3060\u3051\u3067\u306f\u3042\u308b\u304c\u3001\u65b0\u3057\u3044\u30b3\u30df\u30c3\u30c8\u306f\u30cf\u30c3\u30b7\u30e5(SHA-1)\u5024\u304c\u7570\u306a\u308b\u4f3c\u3066\u975e\u306a\u308b\u30b3\u30df\u30c3\u30c8\u3067\u3042\u308b\u3002<\/li>\n<li><code>git add<\/code> \u3084 <code>git rm<\/code> \u3067\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u306b\u5909\u66f4\u3092\u52a0\u3048\u3066\u3044\u308c\u3070\u3001\u5168\u9762\u7684\u306b\u975e\u306a\u308b\u30b3\u30df\u30c3\u30c8\u3067\u3042\u308b\u3002<\/li>\n<\/ol>\n<h3>8. prune (\u5207\u308a\u6255\u3046)<\/h3>\n<h4>8.1. \u30ea\u30e2\u30fc\u30c8\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u5b58\u5728\u3057\u306a\u3044\u30ea\u30e2\u30fc\u30c8\u8ffd\u8de1\u30d6\u30e9\u30f3\u30c1\u3092\u524a\u9664\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git fetch --prune<\/pre>\n<h4>8.2. \u30ef\u30fc\u30af\u30c4\u30ea\u30fc\u60c5\u5831\u3092\u524a\u9664\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git worktree prune<\/pre>\n<h3>9. drop (\u843d\u3068\u3059)<\/h3>\n<h4>9.1. \u6700\u65b0\u306estash\u3092\u524a\u9664\u3059\u308b<\/h4>\n<pre class=\"lang:default highlight:0 decode:true \" >$ git stash drop<\/pre>\n<p>\u30ef\u30fc\u30af\u304b\u3089stash(\u9000\u907f)\u3057\u305f\u5185\u5bb9\u3092\u30ef\u30fc\u30af\u306b\u623b\u3055\u305a\u306b\u7834\u68c4\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u3084\u308a\u76f4\u3057\u7cfb\u30b3\u30de\u30f3\u30c9\u300d\u306f\u79c1\u306e\u9020\u8a9e\u3067\u3059\u3002git\u306e\u64cd\u4f5c\u306f\u5e38\u306b\u3084\u308a\u76f4\u305b\u307e\u3059\u3002 \u300c\u6253\u3061\u6d88\u3059\u300d\u3001\u300c\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u300d\u3001\u300c\u524a\u9664\u3059\u308b\u300d\u3001\u300c\u30af\u30ea\u30fc\u30f3\u3059\u308b\u300d\u306a\u3069\u3001\u300c\u3084\u308a\u76f4\u3059\u300d\u305f\u3081\u306egit\u306e\u30b3\u30de\u30f3\u30c9\u3084\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2],"class_list":["post-4416","post","type-post","status-publish","format-standard","hentry","category-memo","tag-git"],"_links":{"self":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/comments?post=4416"}],"version-history":[{"count":29,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4416\/revisions"}],"predecessor-version":[{"id":4446,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/4416\/revisions\/4446"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=4416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=4416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=4416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}