Git にスタッシュを適用する
この記事では、Git でスタッシュを適用するさまざまな方法について説明します。特定の Git スタッシュを適用する手順が表示されます。
Git にスタッシュを適用する
気づいていない場合は、git stash list を使用して Git stash を表示します。
pc@JOHN MINGW64 ~/Git (main) $ git stash list stash@{0}: WIP on main: 78129a6 Revert "$git status" stash@{1}: WIP on main: 195e5c3 $git status Git ブランチに 2つの隠し場所があることがわかります。
git stash apply を実行すると、スタックの最上位がポイントされます。以下に示すように、特定のスタッシュを適用する場合は、引数を追加する必要があります。
$ git stash apply stash@{stash_index} この例では、インデックス 1 スタッシュを適用します。以下のコマンドを実行します。
$ git stash apply stash@{1} Removing text.txt.txt CONFLICT (modify/delete): Tutorial.txt deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of Tutorial.txt left in tree. On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: text.txt.txt modified: text.txt.txt.bak Unmerged paths: (use "git restore --staged <file>..." to unstage) (use "git add/rm <file>..." as appropriate to mark resolution) deleted by us: Tutorial.txt Untracked files: (use "git add <file>..." to include in what will be committed) .bash_history.bak Delftscopetech/ New folder/ file.patch ただし、このコマンドを適用しても、リストからスタッシュは削除されません。git stash pop コマンドを実行する必要があります。
git stash apply と git stash pop の間には違いがあります。後者は変更を適用し、リストから stash を削除します。
例を見てみましょう。
pc@JOHN MINGW64 ~/Git/Delftscopetech (main) $ git stash pop stash@{0} Removing README.md On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: README.md no changes added to commit (use "git add" and/or "git commit -a") Dropped stash@{0} (1531151482186b97f47e9b852ac29ddd194bd099) Git がスタッシュを適用し、上記の出力から削除しているのがわかります。
別の方法は、git stash drop stash@{Index} を実行することです。すべてのスタッシュをクリアするには、git stash clear コマンドを実行します。
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn