LoginSignup
2
1

More than 3 years have passed since last update.

Gitでstashを適用する方法

Last updated at Posted at 2019-07-03
  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • git version 1.8.3.1
    • xfc4-terminal 0.8.7.4

stashする

Gitでstashする方法 - Qiita

stashのファイル全部を適用する場合

書き方 : git stash apply {スタッシュ}

1. 適用対象stashを確認する

# 対象のstashを確認する
$ git stash list
stash@{0}: On branch-c: stash-a
stash@{1}: WIP on branch-d: 32833a9

2.適用する

$ git stash apply stash@{1}
# On branch branch-d
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   project-name/.classpath
#   modified:   project-name/.project
#   modified:   project-name/.settings/org.eclipse.jdt.core.prefs
#   modified:   project-name/.settings/org.eclipse.wst.common.component
#   modified:   project-name/pom.xml
#
no changes added to commit (use "git add" and/or "git commit -a")

ファイルを指定して適用する場合

書き方 : git checkout {スタッシュ} {ファイルパス}
作業中のファイルをgit stashして、一部のファイルだけ戻す - kentana20 技忘録

1. 適用対象ファイルを確認する

# 対象のstashを確認する
$ git stash list
stash@{0}: On branch-c: stash-a
stash@{1}: WIP on branch-d: 32833a9

# 対象のファイルを確認する
$ git stash show stash@{0} | grep pom.xml
 project-name/pom.xml                                             | 26 ++++++++++++++++++++++-

2.適用する

$ git checkout stash@{0} project-name/pom.xml

適用してstashを消す場合

書き方 : git stash pop {スタッシュ}

# 適用するstashを確認する
$ git stash list
stash@{0}: On branch-name: stash-name

# 適用してstashを消す
$ git stash pop stash@{0}
# On branch branch-name
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   my-project/.classpath
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   build/
#   my-project/src/resources/jdbc.properties
#   my-project/target/
no changes added to commit (use "git add" and/or "git commit -a")
Dropped stash@{0} (a63b5722ab1349ff027df8449e6962d247dcab23)

# stashが消えたことを確認する
$ git stash list
$
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1