teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

Add expression

2020/07/24 02:11

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -1,2 +1,91 @@
1
1
  a ファイルをファイルとして追加しただけで、 Git 管理に追加していなければ、
2
- 通常の `stash` コマンドではファイルは `stash` 領域に待避されません
2
+ 通常の `stash` コマンドではファイルは `stash` 領域に待避されません
3
+
4
+ ## 実験
5
+
6
+ Git 管理に追加されていないファイルは
7
+ `stash` しても `stash` 領域に待避されません:
8
+
9
+ ```console
10
+ $ git status
11
+ On branch master
12
+ Untracked files:
13
+ (use "git add <file>..." to include in what will be committed)
14
+ test.txt
15
+
16
+ nothing added to commit but untracked files present (use "git add" to track)
17
+
18
+ $ git stash
19
+ No local changes to save
20
+
21
+ $ git status
22
+ On branch master
23
+ Untracked files:
24
+ (use "git add <file>..." to include in what will be committed)
25
+ test.txt
26
+
27
+ nothing added to commit but untracked files present (use "git add" to track)
28
+ ```
29
+
30
+ Git 管理に追加すると `stash` は成功します:
31
+
32
+ ```console
33
+ $ git add test.txt
34
+
35
+ $ git stash
36
+ Saved working directory and index state WIP on master: 68829db First commit
37
+
38
+ $ git status
39
+ On branch master
40
+ nothing to commit, working tree clean
41
+
42
+ $ git stash list
43
+ stash@{0}: WIP on master: 68829db First commit
44
+
45
+ $ git stash show 0
46
+ test.txt | 1 +
47
+ 1 file changed, 1 insertion(+)
48
+ ```
49
+
50
+ この場合は `checkout` してもファイルはワーキングツリーではなく
51
+ `stash` 領域に存在します:
52
+
53
+ ```console
54
+ $ git checkout -b feature
55
+ Switched to a new branch 'feature'
56
+
57
+ $ git status
58
+ On branch feature
59
+ nothing to commit, working tree clean
60
+
61
+ $ git stash list
62
+ stash@{0}: WIP on master: 68829db First commit
63
+
64
+ $ git stash show 0
65
+ test.txt | 1 +
66
+ 1 file changed, 1 insertion(+)
67
+ ```
68
+
69
+ もし、Git 管理されていないファイルがワーキングツリーにある状態で `checkout` が成功すると、
70
+ ファイルはワーキングツリーに残ったままになります:
71
+
72
+ ```console
73
+ $ git status
74
+ On branch master
75
+ Untracked files:
76
+ (use "git add <file>..." to include in what will be committed)
77
+ test.txt
78
+
79
+ nothing added to commit but untracked files present (use "git add" to track)
80
+
81
+ $ git checkout -b feature
82
+ Switched to a new branch 'feature'
83
+
84
+ $ git status
85
+ On branch feature
86
+ Untracked files:
87
+ (use "git add <file>..." to include in what will be committed)
88
+ test.txt
89
+
90
+ nothing added to commit but untracked files present (use "git add" to track)
91
+ ```