当前目录的 git 存储后兄弟目录丢失
Sibling directories lost after git stash of current directory
假设我有这个目录结构:
project_root
|
+--parent
|
+--child
|
+--baby_brother
baby_brother
是一个新目录,未被 git 跟踪。我对 child
中的文件也有很多更改。我需要临时访问 child
中以前版本的文件,所以我想我只是隐藏我的更改:
cd $project_root/parent/child
git stash push .
然后:
cd $project_root/parent/child
git stash pop
现在,令我非常沮丧的是,baby_brother
连同一周的工作都不见了。 :-(
我有两个问题:
有什么方法可以找回我的文件吗?我怀疑答案是 "no".
这是一个错误,还是我做错了什么?
我看到 an SO question 说 git 删除未跟踪文件是预期的行为,但其中一个,它还说这已在 1.7.1.1 中修复(我使用的是 2.13 .0),对于两个,我希望存储只影响 child
,因为我在该目录中并在命令末尾包含一个点以引用当前目录。
这是一个演示问题的快速重现:
1 ~ % mkdir project_root
2 ~ % cd project_root
3 project_root % mkdir parent
4 project_root % touch parent/file
5 project_root % mkdir parent/child
6 project_root % touch parent/child/file2
7 project_root % git init
Initialized empty Git repository in /home/pdaddy/project_root/.git/
8 project_root % git add .
9 project_root % git commit -m 'Get it in git'
[master (root-commit) 2d0872c] Get it in git
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 parent/child/file2
create mode 100644 parent/file
10 project_root % mkdir parent/baby_brother
11 project_root % touch parent/baby_brother/file3
12 project_root % touch parent/file4
13 project_root % touch file5
14 project_root % comment="As it turns out, file4 and file5 will be deleted, too."
15 project_root % tree $PWD
/home/pdaddy/project_root
|-- file5
`-- parent
|-- baby_brother
| `-- file3
|-- child
| `-- file2
|-- file
`-- file4
3 directories, 3 files
16 project_root % echo 'some changes' >> parent/child/file2
17 project_root % cd parent/child
18 child % git stash push .
Saved working directory and index state WIP on master: 2d0872c Get it in git
19 project_root % tree ~/project_root
/home/pdaddy/project_root
`-- parent
|-- child
| `-- file2
`-- file
2 directories, 2 files
20 child % git stash pop
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: file2
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (80e41d0ed1f2b0a085d4f5ca3a38833a18873f98)
21 child % tree ~/project_root
/home/pdaddy/project_root
`-- parent
|-- child
| `-- file2
`-- file
2 directories, 2 files
我用 git 的 next 分支 (v2.14.0.rc0) 测试了我的重现示例,但问题并没有出现,所以我猜这是一个错误,并且有人提交了修复程序。
假设我有这个目录结构:
project_root | +--parent | +--child | +--baby_brother
baby_brother
是一个新目录,未被 git 跟踪。我对 child
中的文件也有很多更改。我需要临时访问 child
中以前版本的文件,所以我想我只是隐藏我的更改:
cd $project_root/parent/child
git stash push .
然后:
cd $project_root/parent/child
git stash pop
现在,令我非常沮丧的是,baby_brother
连同一周的工作都不见了。 :-(
我有两个问题:
有什么方法可以找回我的文件吗?我怀疑答案是 "no".
这是一个错误,还是我做错了什么?
我看到 an SO question 说 git 删除未跟踪文件是预期的行为,但其中一个,它还说这已在 1.7.1.1 中修复(我使用的是 2.13 .0),对于两个,我希望存储只影响 child
,因为我在该目录中并在命令末尾包含一个点以引用当前目录。
这是一个演示问题的快速重现:
1 ~ % mkdir project_root 2 ~ % cd project_root 3 project_root % mkdir parent 4 project_root % touch parent/file 5 project_root % mkdir parent/child 6 project_root % touch parent/child/file2 7 project_root % git init Initialized empty Git repository in /home/pdaddy/project_root/.git/ 8 project_root % git add . 9 project_root % git commit -m 'Get it in git' [master (root-commit) 2d0872c] Get it in git 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 parent/child/file2 create mode 100644 parent/file 10 project_root % mkdir parent/baby_brother 11 project_root % touch parent/baby_brother/file3 12 project_root % touch parent/file4 13 project_root % touch file5 14 project_root % comment="As it turns out, file4 and file5 will be deleted, too." 15 project_root % tree $PWD /home/pdaddy/project_root |-- file5 `-- parent |-- baby_brother | `-- file3 |-- child | `-- file2 |-- file `-- file4 3 directories, 3 files 16 project_root % echo 'some changes' >> parent/child/file2 17 project_root % cd parent/child 18 child % git stash push . Saved working directory and index state WIP on master: 2d0872c Get it in git 19 project_root % tree ~/project_root /home/pdaddy/project_root `-- parent |-- child | `-- file2 `-- file 2 directories, 2 files 20 child % git stash pop On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: file2 no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (80e41d0ed1f2b0a085d4f5ca3a38833a18873f98) 21 child % tree ~/project_root /home/pdaddy/project_root `-- parent |-- child | `-- file2 `-- file 2 directories, 2 files
我用 git 的 next 分支 (v2.14.0.rc0) 测试了我的重现示例,但问题并没有出现,所以我猜这是一个错误,并且有人提交了修复程序。