Created
August 28, 2021 01:54
-
-
Save yoichi/c44f19798f48bb32fb27d4b20f7ce7e8 to your computer and use it in GitHub Desktop.
Understanding git stash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Understanding git stash", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyOFiwJX0oFTm+R1aPwJFLp5", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/yoichi/c44f19798f48bb32fb27d4b20f7ce7e8/understanding-git-stash.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ailThzGyO7Jl" | |
}, | |
"source": [ | |
"# Understanding git stash" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "OqB7htewPv6q" | |
}, | |
"source": [ | |
"## git stash の使い方" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "_ulQSyGzPevo" | |
}, | |
"source": [ | |
"リポジトリを作る" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "GPtKoYzoOnLV" | |
}, | |
"source": [ | |
"!git config --global user.email \"foo@example.com\"\n", | |
"!git config --global user.name \"Foo Bar\"" | |
], | |
"execution_count": 91, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "-R3yf4lHMGZC", | |
"outputId": "512c7621-9068-4ed3-e0bb-5c7b9d560efb" | |
}, | |
"source": [ | |
"%cd\n", | |
"!rm -rf repository\n", | |
"%mkdir -p repository\n", | |
"%cd repository\n", | |
"!ls -a" | |
], | |
"execution_count": 92, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"/root\n", | |
"/root/repository\n", | |
". ..\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "qdIws0utOiIc", | |
"outputId": "9441dae7-fe3a-4753-b61b-7ae63d84200b" | |
}, | |
"source": [ | |
"!git init" | |
], | |
"execution_count": 93, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Initialized empty Git repository in /root/repository/.git/\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "CaXLpNkSOihU", | |
"outputId": "dc90765b-5a7b-4c83-b552-35b75b4255b1" | |
}, | |
"source": [ | |
"!ls -a" | |
], | |
"execution_count": 94, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
". .. .git\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "jRKl_gfwP5n7" | |
}, | |
"source": [ | |
"最初のコミット" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "3YoywqCNND_Z", | |
"outputId": "80b9c52f-24f5-471d-d791-4f7e9ac93996" | |
}, | |
"source": [ | |
"!echo aaa > readme\n", | |
"!cat readme\n", | |
"!git add readme\n", | |
"!git commit -m \"initial commit\"" | |
], | |
"execution_count": 95, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"aaa\n", | |
"[master (root-commit) d97f061] initial commit\n", | |
" 1 file changed, 1 insertion(+)\n", | |
" create mode 100644 readme\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "v90tV3ZQP-gS" | |
}, | |
"source": [ | |
"作業ツリーに変更を加える" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "o_ZhgbOENqw_" | |
}, | |
"source": [ | |
"!echo bbb >> readme" | |
], | |
"execution_count": 96, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "LMdx00WSN-85", | |
"outputId": "687de511-f877-45c4-8015-bf7cdeb4dcec" | |
}, | |
"source": [ | |
"!git diff" | |
], | |
"execution_count": 97, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex 72943a1..dbee026 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1 +1,2 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mbbb\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "cjiYbzt2N76s", | |
"outputId": "bc68bc75-bcbc-4361-c146-764dfc118c79" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 98, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"Changes not staged for commit:\n", | |
" (use \"git add <file>...\" to update what will be committed)\n", | |
" (use \"git checkout -- <file>...\" to discard changes in working directory)\n", | |
"\n", | |
"\t\u001b[31mmodified: readme\u001b[m\n", | |
"\n", | |
"no changes added to commit (use \"git add\" and/or \"git commit -a\")\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JS_4Fc4_QEOW" | |
}, | |
"source": [ | |
"git stash saveで作業ツリーの変更を退避" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "8YGaJ70ANxon", | |
"outputId": "2b000341-5507-4565-a286-4482e15c2d27" | |
}, | |
"source": [ | |
"!git stash save" | |
], | |
"execution_count": 99, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Saved working directory and index state WIP on master: d97f061 initial commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "mESUbit9ONLR", | |
"outputId": "34ab8343-5129-44e8-ef36-1cd6dd009404" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 100, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"nothing to commit, working tree clean\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Kb603z1XQJSM" | |
}, | |
"source": [ | |
"git stash popで退避させてたものを作業ツリーに戻す" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "7ORC5FcrOROT", | |
"outputId": "4fe46691-9f1d-4a2b-eec3-bb770a8b215c" | |
}, | |
"source": [ | |
"!git stash pop" | |
], | |
"execution_count": 101, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"Changes not staged for commit:\n", | |
" (use \"git add <file>...\" to update what will be committed)\n", | |
" (use \"git checkout -- <file>...\" to discard changes in working directory)\n", | |
"\n", | |
"\t\u001b[31mmodified: readme\u001b[m\n", | |
"\n", | |
"no changes added to commit (use \"git add\" and/or \"git commit -a\")\n", | |
"Dropped refs/stash@{0} (c8a88d39f7f38506d70aecfddc90d629fc70e0ad)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "lBKL1NaTOU5V", | |
"outputId": "7ac8fdcb-42f2-46ad-ed9d-008612fddf51" | |
}, | |
"source": [ | |
"!git diff" | |
], | |
"execution_count": 102, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex 72943a1..dbee026 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1 +1,2 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mbbb\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "kacn5hnQQUSI" | |
}, | |
"source": [ | |
"作業ツリーの変更を破棄" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "fGop9R0IOtX8", | |
"outputId": "443378cc-4023-41cd-ba75-1446ff671492" | |
}, | |
"source": [ | |
"!git stash save\n", | |
"!git stash drop" | |
], | |
"execution_count": 103, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Saved working directory and index state WIP on master: d97f061 initial commit\n", | |
"Dropped refs/stash@{0} (6a2f795afaa01e28f15496ad48e0f23dac8cd613)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "6U8zf463O1wm", | |
"outputId": "3a0d684b-b0c5-4f10-9dee-4d62d199a655" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 104, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"nothing to commit, working tree clean\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "hxGz4cQZO3Sf", | |
"outputId": "ad227df5-e667-4c33-cdf0-dcd9e6a04581" | |
}, | |
"source": [ | |
"!cat readme" | |
], | |
"execution_count": 105, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"aaa\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "11qX4WbiQZIk" | |
}, | |
"source": [ | |
"## gitのデータ構造のおさらい" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "E5Am2iMjRBHY" | |
}, | |
"source": [ | |
"もう一つコミットしておく" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "lucIODkKRdTp", | |
"outputId": "63fa2c76-7712-4e7e-aeb9-e53998f72a20" | |
}, | |
"source": [ | |
"!git log" | |
], | |
"execution_count": 106, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[33mcommit d97f0610338edcfecc660ad2580367a7e0123bfd\u001b[m\u001b[33m (\u001b[m\u001b[1;36mHEAD -> \u001b[m\u001b[1;32mmaster\u001b[m\u001b[33m)\u001b[m\n", | |
"Author: Foo Bar <foo@example.com>\n", | |
"Date: Sat Aug 28 01:47:41 2021 +0000\n", | |
"\n", | |
" initial commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "GlSCCSDOQ887", | |
"outputId": "b9afbec3-e64c-4266-85a2-5c3415db75fc" | |
}, | |
"source": [ | |
"!echo bbb >> readme\n", | |
"!git commit -am \"2nd commit\"" | |
], | |
"execution_count": 107, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"[master afed682] 2nd commit\n", | |
" 1 file changed, 1 insertion(+)\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "P7-ry3FxSJRY", | |
"outputId": "e010025f-7b11-4a36-e7da-c461e3151bc2" | |
}, | |
"source": [ | |
"!git log" | |
], | |
"execution_count": 108, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[33mcommit afed682462432dac0f7c40d1df8089766d22ae6f\u001b[m\u001b[33m (\u001b[m\u001b[1;36mHEAD -> \u001b[m\u001b[1;32mmaster\u001b[m\u001b[33m)\u001b[m\n", | |
"Author: Foo Bar <foo@example.com>\n", | |
"Date: Sat Aug 28 01:48:21 2021 +0000\n", | |
"\n", | |
" 2nd commit\n", | |
"\n", | |
"\u001b[33mcommit d97f0610338edcfecc660ad2580367a7e0123bfd\u001b[m\n", | |
"Author: Foo Bar <foo@example.com>\n", | |
"Date: Sat Aug 28 01:47:41 2021 +0000\n", | |
"\n", | |
" initial commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "hAkvTBcfSOQl" | |
}, | |
"source": [ | |
"commit オブジェクト" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "mRR0hEmDSR2z", | |
"outputId": "425ca298-0c97-4281-ee8f-da0d10e77e28" | |
}, | |
"source": [ | |
"!git cat-file -t afed682462432dac0f7c40d1df8089766d22ae6f " | |
], | |
"execution_count": 109, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "muUT30OgSWmj", | |
"outputId": "63c9d7b2-37ef-4310-a0ca-8497fe118ea0" | |
}, | |
"source": [ | |
"!git cat-file -p afed682462432dac0f7c40d1df8089766d22ae6f " | |
], | |
"execution_count": 110, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"tree 3b150b3e15a1d27676471631461d8fe8aab1efa1\n", | |
"parent d97f0610338edcfecc660ad2580367a7e0123bfd\n", | |
"author Foo Bar <foo@example.com> 1630115301 +0000\n", | |
"committer Foo Bar <foo@example.com> 1630115301 +0000\n", | |
"\n", | |
"2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "RNuem2RpUyyi" | |
}, | |
"source": [ | |
"tree オブジェクト" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "OxtIZzX-U3t8", | |
"outputId": "5820a73f-f3ec-4ad0-bef8-7c656c8b6afa" | |
}, | |
"source": [ | |
"!git cat-file -t 3b150b3e15a1d27676471631461d8fe8aab1efa1" | |
], | |
"execution_count": 111, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"tree\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "KeuWCldtU_Fi", | |
"outputId": "33621190-9641-48da-971d-c8f323b000b1" | |
}, | |
"source": [ | |
"!git cat-file -p 3b150b3e15a1d27676471631461d8fe8aab1efa1" | |
], | |
"execution_count": 112, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"100644 blob dbee0265d31298531773537e6e37e4fd1ee71d62\treadme\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "aeppY33VU3Kx" | |
}, | |
"source": [ | |
"blob オブジェクト" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "qGVrKso5VCbF", | |
"outputId": "545a0fab-576b-448f-edf0-215a1539282d" | |
}, | |
"source": [ | |
"!git cat-file -t dbee0265d31298531773537e6e37e4fd1ee71d62" | |
], | |
"execution_count": 113, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"blob\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Nh2ctWXxVGQd", | |
"outputId": "1e1248b5-6692-41de-d73c-bc77411644a0" | |
}, | |
"source": [ | |
"!git cat-file -p dbee0265d31298531773537e6e37e4fd1ee71d62" | |
], | |
"execution_count": 114, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"aaa\n", | |
"bbb\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "dvDAJC-LVTEi" | |
}, | |
"source": [ | |
"git のデータ構造まとめ\n", | |
"\n", | |
"* commit オブジェクト\n", | |
" * コンテンツはコミットメッセージなど\n", | |
" * parent commit, root treeを参照する\n", | |
"* tree オブジェクト\n", | |
" * コンテンツは含んでいるディレクトリ、ファイルの名前\n", | |
" * tree,blobを参照\n", | |
"* blob オブジェクト\n", | |
" * コンテンツはファイルの中身" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "YvIhQN3gWSGR" | |
}, | |
"source": [ | |
"## git stashの仕組み" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "TUkjV6gvWhIf", | |
"outputId": "d3dee3d2-401b-402a-ba75-1485167666a9" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 115, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"nothing to commit, working tree clean\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ottSGSj2WmbE" | |
}, | |
"source": [ | |
"!echo ccc >> readme\n", | |
"!git add readme" | |
], | |
"execution_count": 116, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ttk8wcShWu-1" | |
}, | |
"source": [ | |
"!echo ddd >> readme" | |
], | |
"execution_count": 117, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "oKIKo58RWzRG", | |
"outputId": "6ca47191-a31c-4d95-f08e-6d3a44acdee6" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 118, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"Changes to be committed:\n", | |
" (use \"git reset HEAD <file>...\" to unstage)\n", | |
"\n", | |
"\t\u001b[32mmodified: readme\u001b[m\n", | |
"\n", | |
"Changes not staged for commit:\n", | |
" (use \"git add <file>...\" to update what will be committed)\n", | |
" (use \"git checkout -- <file>...\" to discard changes in working directory)\n", | |
"\n", | |
"\t\u001b[31mmodified: readme\u001b[m\n", | |
"\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "uS5-_5x2W7pH", | |
"outputId": "1f2f1dbf-a7e7-4ca0-8cad-604987cd5176" | |
}, | |
"source": [ | |
"!git diff --cached" | |
], | |
"execution_count": 119, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex dbee026..1802a74 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1,2 +1,3 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
" bbb\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mccc\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "gQNqm2jVW2jz", | |
"outputId": "6b22f8b9-ce5f-46e3-930e-3ac52c5a3832" | |
}, | |
"source": [ | |
"!git diff" | |
], | |
"execution_count": 120, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex 1802a74..35fbd83 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1,3 +1,4 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
" bbb\u001b[m\n", | |
" ccc\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mddd\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "JXx2BmQNXIDG", | |
"outputId": "caf36bdc-85c4-49ff-9be4-ab1a0fd0cc5e" | |
}, | |
"source": [ | |
"!git stash save" | |
], | |
"execution_count": 121, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Saved working directory and index state WIP on master: afed682 2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "2gezcUdWXKlj", | |
"outputId": "01bf723a-c522-49c3-d54c-53e56b184c71" | |
}, | |
"source": [ | |
"!git status" | |
], | |
"execution_count": 122, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"On branch master\n", | |
"nothing to commit, working tree clean\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "zRQxjU0wXMac", | |
"outputId": "dd5a885f-f676-409d-b8ee-1fdef7b1db20" | |
}, | |
"source": [ | |
"!git stash list" | |
], | |
"execution_count": 123, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"stash@{0}: WIP on master: afed682 2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "wZiap4SaXPZP", | |
"outputId": "b554f1e4-472c-472d-8675-844f01d7f6e9" | |
}, | |
"source": [ | |
"!find .git -name stash" | |
], | |
"execution_count": 124, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
".git/logs/refs/stash\n", | |
".git/refs/stash\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "K_cZkF1pXZio", | |
"outputId": "44fef718-6ce4-42a3-bae5-068a7d1edda8" | |
}, | |
"source": [ | |
"!cat .git/refs/stash" | |
], | |
"execution_count": 125, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"d104212ba8ae41627e602ca525c52c3d00510130\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "PY9eApMOX4ZX" | |
}, | |
"source": [ | |
"オブジェクトっぽい。何者か見てみる" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "HjOQaPqOYEmY", | |
"outputId": "850544bd-d9ba-4608-af82-2c10adfe73af" | |
}, | |
"source": [ | |
"!git cat-file -t d104212ba8ae41627e602ca525c52c3d00510130" | |
], | |
"execution_count": 126, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "prVHUP-uYiyH", | |
"outputId": "b55f32fe-1dce-47d0-eb60-13fdb3c39424" | |
}, | |
"source": [ | |
"!git cat-file -p d104212ba8ae41627e602ca525c52c3d00510130" | |
], | |
"execution_count": 127, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"tree 99d4398f76d33e40b4fe1b0a4dfecfcff270ca74\n", | |
"parent afed682462432dac0f7c40d1df8089766d22ae6f\n", | |
"parent a35abfc1fa8feaaab944c61d895d7d1d3099dee8\n", | |
"author Foo Bar <foo@example.com> 1630115390 +0000\n", | |
"committer Foo Bar <foo@example.com> 1630115390 +0000\n", | |
"\n", | |
"WIP on master: afed682 2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "3lfCAuoZYqxp", | |
"outputId": "4addbd94-ab1e-4e3c-ffe7-6fefb5cc87fc" | |
}, | |
"source": [ | |
"!git log --oneline --graph d104212ba8ae41627e602ca525c52c3d00510130" | |
], | |
"execution_count": 128, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"* \u001b[33md104212\u001b[m\u001b[33m (\u001b[m\u001b[1;35mrefs/stash\u001b[m\u001b[33m)\u001b[m WIP on master: afed682 2nd commit\n", | |
"\u001b[31m|\u001b[m\u001b[32m\\\u001b[m \n", | |
"\u001b[31m|\u001b[m * \u001b[33ma35abfc\u001b[m index on master: afed682 2nd commit\n", | |
"\u001b[31m|\u001b[m\u001b[31m/\u001b[m \n", | |
"* \u001b[33mafed682\u001b[m\u001b[33m (\u001b[m\u001b[1;36mHEAD -> \u001b[m\u001b[1;32mmaster\u001b[m\u001b[33m)\u001b[m 2nd commit\n", | |
"* \u001b[33md97f061\u001b[m initial commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "K_EDpszEZTyw", | |
"outputId": "8a7b9a17-97a0-43ea-bc58-01e357714d35" | |
}, | |
"source": [ | |
"!git diff afed682..a35abfc" | |
], | |
"execution_count": 129, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex dbee026..1802a74 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1,2 +1,3 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
" bbb\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mccc\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "8p0Lj1mZZdyc", | |
"outputId": "cfa571e9-4d59-40a6-efd6-f0b647521574" | |
}, | |
"source": [ | |
"!git diff a35abfc..d104212" | |
], | |
"execution_count": 130, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mdiff --git a/readme b/readme\u001b[m\n", | |
"\u001b[1mindex 1802a74..35fbd83 100644\u001b[m\n", | |
"\u001b[1m--- a/readme\u001b[m\n", | |
"\u001b[1m+++ b/readme\u001b[m\n", | |
"\u001b[36m@@ -1,3 +1,4 @@\u001b[m\n", | |
" aaa\u001b[m\n", | |
" bbb\u001b[m\n", | |
" ccc\u001b[m\n", | |
"\u001b[32m+\u001b[m\u001b[32mddd\u001b[m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "HIZHpiuuZomW" | |
}, | |
"source": [ | |
"stash は commit オブジェクト\n", | |
"* HEAD と、index の状態を commit にしたものとのマージコミット\n", | |
"* マージコミットの差分が作業ツリーの変更\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "5HpBhOeTbOoX" | |
}, | |
"source": [ | |
"リポジトリ内のもう一つのファイル" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "E5rVDcplXdlD", | |
"outputId": "77e28347-76f3-4db9-e5a1-144c486e6c61" | |
}, | |
"source": [ | |
"!cat .git/logs/refs/stash" | |
], | |
"execution_count": 131, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"0000000000000000000000000000000000000000 d104212ba8ae41627e602ca525c52c3d00510130 Foo Bar <foo@example.com> 1630115390 +0000\tWIP on master: afed682 2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "UMnParDJXrs_", | |
"outputId": "5b15ca91-1cac-45f9-f252-63e4580831e0" | |
}, | |
"source": [ | |
"!git reflog stash" | |
], | |
"execution_count": 132, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[33md104212\u001b[m\u001b[33m (\u001b[m\u001b[1;35mrefs/stash\u001b[m\u001b[33m)\u001b[m stash@{0}: WIP on master: afed682 2nd commit\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "TIMy775Qba4y" | |
}, | |
"source": [ | |
"git stash list は refs/stash の reflog を見てる。" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "jF-DexQLb8zL" | |
}, | |
"source": [ | |
"stash のまとめ\n", | |
"* stash はマージコミットである\n", | |
"* 複数のstashはreflogで管理されている\n", | |
"\n", | |
"\n", | |
"ちなみに git stash save -u したときは untracked files が orphan commit になって octopus merge したものが stash になる\n", | |
"https://yoichi22.hatenablog.com/entry/2020/05/21/081044" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment