SYNOPSIS
git stash list [<log-options>]
git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>]
git stash drop [-q | --quiet] [<stash>]
git stash pop [--index] [-q | --quiet] [<stash>]
git stash apply [--index] [-q | --quiet] [<stash>]
git stash branch <branchname> [<stash>]
git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
[-u | --include-untracked] [-a | --all] [(-m | --message) <message>]
[--pathspec-from-file=<file> [--pathspec-file-nul]]
[--] [<pathspec>...]]
git stash save [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
[-u | --include-untracked] [-a | --all] [<message>]
git stash clear
git stash create [<message>]
git stash store [(-m | --message) <message>] [-q | --quiet] <commit>
git stash export (--print | --to-ref <ref>) [<stash>...]
git stash import <commit>
DESCRIPTION
作業ディレクトリとインデックスの現在の状態を記録したいが、 作業ディレクトリをクリーンな状態に戻したい場合は、 git stash を使用します。 このコマンドは、ローカルの変更を保存し、 作業ディレクトリを元に戻して(revert)、HEAD コミットに一致させます。
The modifications stashed away by this command can be listed with git stash list, inspected with git stash show, and restored (potentially on top of a different commit) with git stash apply. Calling git stash without any arguments is equivalent to git stash push. A stash is by default listed as "WIP on <branchname> …", but you can give a more descriptive message on the command line when you create one.
The latest stash you created is stored in refs/stash; older stashes are found in the reflog of this reference and can be named using the usual reflog syntax (e.g. stash@{0} is the most recently created stash, stash@{1} is the one before it, stash@{2.hours.ago} is also possible). Stashes may also be referenced by specifying just the stash index (e.g. the integer <n> is equivalent to stash@{<n>}).
COMMANDS
-
push[-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [(-m|--message) <message>] [--pathspec-from-file=<file> [--pathspec-file-nul]] [--] [<pathspec>...] -
Save your local modifications to a new stash entry and roll them back to
HEAD(in the working tree and in the index). The <message> part is optional and gives the description along with the stashed state.スナップショットを素早く作成する場合、「push」を省略できます。 このモードでは、 誤ったサブ・コマンドが意図しないスタッシュ・エントリを作成するのを防ぐため、 オプション以外の引数は許可されません。 これには例外が2つあり、
stash-pはstashpush-pのエイリアスとして機能し、 pathspec 要素は曖昧さを避けるためにダブルハイフン--の後ろで許可されます。 -
save[-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>] -
このオプションは廃止され、
gitstashpushが採用されました。 pathspecをとることができないという点で「stash push」とは異なります。 代わりに、オプション以外のすべての引数が連結されて、スタッシュメッセージが形成されます。 -
list[<log-options>] -
現在持っているスタッシュエントリを一覧表示します。 各「スタッシュエントリ」は、その名前(たとえば、
stash@{0} は最新のエントリ、stash@{1} はその前のエントリ、など)と、 エントリが作成されたときの現在のブランチの名前と、エントリが基づいていたコミットの簡単な説明と、ともに一覧表示されます。stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation stash@{1}: On master: 9cc0589... Add git-stashこのコマンドは、
gitlogコマンドに適用可能なオプションを使用して、表示内容と方法を制御します。 git-log(1) を参照してください。 -
show[-u|--include-untracked|--only-untracked] [<diff-options>] [<stash>] -
Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g.,
gitstashshow-pstash@{1} to view the second most recent entry in patch form). If no <diff-option> is provided, the default behavior will be given by thestash.showStat, andstash.showPatchconfig variables. You can also usestash.showIncludeUntrackedto set whether--include-untrackedis enabled by default. -
pop[--index] [-q|--quiet] [<stash>] -
スタッシュリストから単一のスタッシュ状態を削除し、現在の作業ツリー状態の上に適用(apply)します。つまり、
gitstashpushの逆の操作を実行します。 作業ディレクトリはインデックスと一致している必要があります。状態の適用(apply)は、競合で失敗する可能性があります。 この場合、スタッシュリストからは削除されません。 競合を手動で解決し、後で手動で
gitstashdropを呼び出す必要があります。 -
apply[--index] [-q|--quiet] [<stash>] -
popと似ていますが、 スタッシュ・リストから状態を削除しません。popとは異なり、 <stash> は、stashpushまたはstashcreateによって作成されたコミットのように見える任意のコミットでかまいません。 -
branch<branchname> [<stash>] -
Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. If that succeeds, and <stash> is a reference of the form
stash@{<revision>}, it then drops the <stash>.これは、
gitstashpushを実行したブランチがすごく変更されていて、gitstashapplyが競合のために失敗した場合に便利です。 スタッシュ・エントリは、gitstashが実行された時点での HEAD であったコミットの上に適用されるため、 元のスタッシュ状態を競合なく復元します。 -
clear -
Remove all the stash entries. Note that those entries will then be subject to pruning, and may be impossible to recover (see EXAMPLES below for a possible strategy).
-
drop[-q|--quiet] [<stash>] -
スタッシュ・エントリー・リストからスタッシュ・エントリを1つ削除します。
-
create -
スタッシュ・エントリー(通常のコミット・オブジェクト)を作成し、 そのオブジェクト名を返しますが、 ref 名前空間にはどこにも保存しません。 これはスクリプトで使用することを目的としています。 おそらくあなたが通常使用したいコマンドではありません。 上記「push」をご覧ください。
-
store -
gitstashcreateで作成された指定のスタッシュ(宙ぶらりんマージコミット(dangling merge commit))をスタッシュ ref に保存し、 スタッシュ reflog を更新します。 これはスクリプトで使用することを目的としています。 おそらくあなたが通常使用したいコマンドではありません。上記の「push」を参照してください。 -
export(--print|--to-ref<ref> ) [<stash>...] -
Export the specified stashes, or all of them if none are specified, to a chain of commits which can be transferred using the normal fetch and push mechanisms, then imported using the
importsubcommand. -
import<commit> -
Import the specified stashes from the specified commit, which must have been created by
export, and add them to the list of stashes. To replace the existing stashes, useclearfirst.
OPTIONS
-
-a -
--all -
このオプションは、
pushとsaveコマンドのみ有効です。無視され追跡されていないすべてのファイルもスタッシュしてから、
gitcleanでクリーンアップします。 -
-u -
--include-untracked -
--no-include-untracked -
pushおよびsaveコマンドと一緒に使用すると、追跡されていないすべてのファイルもスタッシュし、gitcleanでクリーンアップします。showコマンドと一緒に使用すると、diffの一部としてスタッシュエントリの追跡されていないファイルを表示します。 -
--only-untracked -
このオプションは
showコマンドでのみ有効です。diffの一部として、スタッシュエントリ内の、追跡されていないファイル(untracked files)のみを表示します。
-
--index -
このオプションは、
popおよびapplyコマンドにのみ有効です。作業ツリーの変更だけでなく、インデックスの変更も復元しようと試みます。 ただし、競合がある場合(競合がインデックスに保存されているため、元の変更を適用できなくなる)、これは失敗する可能性があります。
-
-k -
--keep-index -
--no-keep-index -
このオプションは、
pushとsaveコマンドのみ有効です。インデックスにすでに追加されているすべての変更はそのまま残ります。
-
-p -
--patch -
このオプションは、
pushとsaveコマンドのみ有効です。HEADと作業ツリー間のdiffから、スタッシュするハンクを対話的に選択します。 スタッシュエントリは、リポジトリのインデックス状態と同じになるように構築され、そのワークツリーには、対話的に選択した変更点のみが含まれます。 そして、選択した変更はワークツリーから巻き戻されます。
--patchモードの操作方法については、 git-add(1) の「Interactive Mode」セクションを参照してください。--patchオプションは--keep-indexの指定を含んでいます。あなたは--no-keep-indexを使用してこれを上書きできます。 -
-U<n> -
--unified=<n> -
コンテキストの「<n>行」の diff を生成します。 デフォルトは
diff.context、 または構成オプションが設定されていない場合は 3 です。 -
--inter-hunk-context=<n> -
指定の「<number>行」までの diff ハンク間のコンテキストを表示し、 それによって互いに近いハンクを融合します。 デフォルトは
diff.interHunkContext、 または構成オプションが設定されていない場合は 0 です。 -
-S -
--staged -
このオプションは、
pushとsaveコマンドのみ有効です。現在ステージングされている変更のみをスタッシュします。 これは、状態が現在のブランチではなくスタッシュにコミットされることを除いて、基本的な
gitcommitに似ています。--patchオプションはこれよりも優先されます。 -
--pathspec-from-file=<file> -
このオプションは、
pushコマンドにのみ有効です。Pathspec is passed in <file> instead of commandline args. If <file> is exactly
-then standard input is used. Pathspec elements are separated by LF or CR/LF. Pathspec elements can be quoted as explained for the configuration variablecore.quotePath(see git-config(1)). See also--pathspec-file-nuland global--literal-pathspecs. -
--pathspec-file-nul -
このオプションは、
pushコマンドにのみ有効です。このオプションは
--pathspec-from-fileでのみ意味があります。 pathspec要素はNUL文字で区切られ、他のすべての文字は文字通りに解釈されます(改行と引用符を含む)。 -
-q -
--quiet -
このオプションは、
apply,drop,pop,push,save,storeコマンドにのみ有効です。静かにして、フィードバックメッセージを抑制します。
-
--print -
This option is only valid for the
exportcommand.Create the chain of commits representing the exported stashes without storing it anywhere in the ref namespace and print the object ID to standard output. This is designed for scripts.
-
--to-ref -
This option is only valid for the
exportcommand.Create the chain of commits representing the exported stashes and store it to the specified ref.
-
-- -
このオプションは、
pushコマンドにのみ有効です。曖昧さ解消の目的のために pathspec をオプションから分離します。
- <pathspec>...
-
このオプションは、
pushコマンドにのみ有効です。新しいスタッシュエントリは、pathspecに一致するファイルについてのみ変更された状態を記録します。 次に、インデックスエントリと作業ツリーファイルは、これらのファイルについてのみHEADの状態に巻き戻されされ、pathspecに一致しないファイルはそのまま残ります。
詳細については、 gitglossary(7) の「pathspec」エントリを参照してください。
- <stash>
-
This option is only valid for
apply,branch,drop,pop,show, andexportcommands.A reference of the form
stash@{<revision>}. When no <stash> is given, the latest stash is assumed (that is,stash@{0}).
DISCUSSION
スタッシュエントリーは、作業ディレクトリの状態を記録するツリーを持つコミットとして表現され、その最初の親はエントリーが作成された HEAD でのコミットとなります。 2番目の親のツリーは、エントリーが作成されたときのインデックスの状態を記録しており、HEAD コミットの子として作られます。 祖先のグラフは以下のようになります:
.----W
/ /
-----H----I
ここで、 H は HEAD コミット、 I はインデックスの状態を記録するコミット、 W は作業ツリーの状態を記録するコミットです。
EXAMPLES
- 変更があるツリーへのプル(Pulling into a dirty tree)
-
作業の途中で、 上流にあなたが取り組んでいる内容に関連する可能性のある変更があることがわかった場合。 あなたのローカルの変更が上流の変更と競合しない場合、 単純な
gitpullで作業を進めることができます。しかし、 あなたのローカルの変更が上流の変更と競合する場合、
gitpullはあなたの変更を上書きすることを拒否します。 そのような場合、 以下のように、 変更をスタッシュに退避させ、 プルを実行してからスタッシュを戻すことができます:$ git pull ... file foobar not up to date, cannot merge. $ git stash $ git pull $ git stash pop - 割り込み作業(Interrupted workflow)
-
作業の途中で上司がやって来て、 すぐに何かを修正するように要求した場合。 従来は、 以下のように、 変更を一時的なブランチにコミットして退避させ、 元のブランチに戻って緊急修正を行う方法が一般的でした:
# ... hack hack hack ... $ git switch -c my_wip $ git commit -a -m "WIP" $ git switch master $ edit emergency fix $ git commit -a -m "Fix in a hurry" $ git switch my_wip $ git reset --soft HEAD^ # ... continue hacking ...これは、
gitstashを使用することで以下のように簡略化できます:# ... hack hack hack ... $ git stash $ edit emergency fix $ git commit -a -m "Fix in a hurry" $ git stash pop # ... continue hacking ... - 局所的なコミットをテスト(Testing partial commits)
-
作業ツリーの変更を2つ以上のコミットに分割したい場合や、 コミット前に各変更をテストしたい場合、
gitstashpush--keep-indexを使用できます:# ... hack hack hack ... $ git add --patch foo # add just first part to the index $ git stash push --keep-index # save all other changes to the stash $ edit/build/test first part $ git commit -m 'First part' # commit fully tested change $ git stash pop # prepare to work on all other changes # ... repeat above five steps until one commit remains ... $ edit/build/test remaining parts $ git commit foo -m 'Remaining parts' - 将来利用するために今取り組んでいる事と無関係な変更を保存
-
大規模な変更の途中で、 忘れたくない無関係な問題を見つけた場合、 その変更を行い、 ステージ後、
gitstashpush--stagedを使って将来のためにスタッシュに退避できます。 これはステージした変更をコミットするのと似ていますが、 コミットは現在のブランチではなくスタッシュに保存されます。# ... hack hack hack ... $ git add --patch foo # add unrelated changes to the index $ git stash push --staged # save these changes to the stash # ... hack hack hack, finish current changes ... $ git commit -m 'Massive' # commit fully tested changes $ git switch fixup-branch # switch to another branch $ git stash pop # to finish work on the saved changes - 誤ってクリアまたはドロップされたスタッシュ・エントリを回復
-
誤ってスタッシュ・エントリをドロップまたはクリアした場合、 通常のセーフティ機構では回復できません。 ただし、 リポジトリー内にまだ存在しているが、 到達できなくなったスタッシュ・エントリの一覧を取得するために、 以下の呪文を試すことができます:
git fsck --unreachable | grep commit | cut -d\ -f3 | xargs git log --merges --no-walk --grep=WIP
CONFIGURATION
このセクションの以下のすべては、 git-config(1) ドキュメントの抜粋です。 内容は git-config(1) ドキュメント にあるものと同一です:
-
stash.index -
これが true に設定されている場合、
gitstashapplyおよびgitstashPopは、--indexが指定されたかのように動作します。 デフォルトは false です。 -
stash.showIncludeUntracked -
これがtrueに設定されている場合、
gitstashshowコマンドはstashエントリの追跡されていないファイル(untracked files)を表示します。 デフォルトはfalseです。 git-stash(1) の「show」コマンドの説明を参照してください。 -
stash.showPatch -
これがtrueに設定されている場合、オプションのない
gitstashshowコマンドは、パッチ形式でstashエントリを表示します。 デフォルトはfalseです。 git-stash(1) の「show」コマンドの説明を参照してください。 -
stash.showStat -
これが true に設定されている場合、 オプションのない
gitstashshowコマンドは、 stash エントリの diffstat を表示します。 デフォルトは true です。 git-stash(1) の「show」コマンドの説明を参照してください。
SEE ALSO
GIT
Part of the git(1) suite