Closed Tunkali closed 7 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.
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?
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.
I just checked, a checkout doesn't seem to delete empty folders.
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>
Reproduce:
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!