fork-dev / TrackerWin

Bug and issue tracker for Fork for Windows
459 stars 10 forks source link

Bug: folder disappears when all (visible) files are removed #2084

Closed Tunkali closed 7 months ago

Tunkali commented 9 months ago

Reproduce:

  1. create a folder with a file inside
  2. commit "added files"
  3. remove the file, but not the folder
  4. checkout previous commit
  5. checkout last commit
  6. Folder disappears

We recently had the issue that an important folder was suddenly disappearing because all files was removed. But the existence of this folder is necessary. We never recognised this kind of issue before.

We tried to reproduce this several times with different results.

The thing with the gitignore couldn't reproduced by us again. But I wanted to mention it, because its seems to be dangerous in special circumstances.

Disappearing of empty folder happens all the time.

Windows 10 / 11 Fork 1.91.2.0 (me) Fork 1.90.x (colleague) Git Instance: 2.42.0windows.2 (all)

thank you!

DanPristupov commented 9 months ago

Git doesn't track folders, it tracks files. If you want to keep an empty folder create and commit some dummy file in it.

Tunkali commented 9 months ago

Hey,

thank you for this fast response. Yes I know that git does not track folders. But, normally it should leave them and not removing folders?

DanPristupov commented 9 months ago

Fork doesn't make checkout itself. It just calls git checkout.

But, normally it [git] should leave them and not removing folders?

Can you show docs? I suppose the point of checkout is to make working directory match a particular commit.

DanPristupov commented 9 months ago

I just checked, a checkout doesn't seem to delete empty folders.

Tunkali commented 9 months ago

image image

DanPristupov commented 9 months ago

Yes, when you remove the files inside, the parent folder will also be deleted. Git in CLI behaves the same:

% mkdir gitfoldertest

% cd gitfoldertest

% git init
Initialized empty Git repository in /Users/dan/src/gitfoldertest/.git/

% mkdir folder

% date > folder/file.txt

% git add . && git commit -m "create file"
[main (root-commit) 86e29e0] create file
 1 file changed, 1 insertion(+)
 create mode 100644 folder/file.txt

% rm -rf folder

% git add . && git commit -m "delete file"
[main c148b5e] delete file
 1 file changed, 1 deletion(-)
 delete mode 100644 folder/file.txt

% git checkout HEAD~
Note: switching to 'HEAD~'.
You are in 'detached HEAD' state.
...
HEAD is now at 86e29e0 create file

% ls
folder

% git checkout main
Previous HEAD position was 86e29e0 create file
Switched to branch 'main'

% ls
<empty>