2

If I am understanding the answers here correctly, git should not track an empty directory, but should not delete it locally. This is not the behavior I am experiencing.

Directory dir_foo/ exists on two computers, A and B. It is full of tracked files. On computer A, my program deletes all of the files in dir_foo/, but leaves the directory intact. I then add/commit/push the changes. On computer B, after pulling, I see that not only are all the files deleted, but dir_foo/ has been deleted locally as well on computer B! (Note that it still exists on computer A.) I think this behavior is incredibly counterintuitive. I do not want this behavior, and, for my use case, cannot specify every directory that git should not delete.

Why is this happening? How can I stop this behavior (without having to specify every empty directory that git should not delete)? Why does the behavior I am experiencing contradict the info in the link above? Thank you.

Reading past this point is not required to answer the question. The info below was requested in the comments.


Screenshots (identifying info removed):

The troublesome directory is results/. The first two screenshots show computers A and B, with the directory and a test file inside:

enter image description here

enter image description here

Next, we remove the file on computer A, leaving the directory intact, commit/push, and observe that the directory is still locally intact on A:

enter image description here

Finally, we pull on computer B, and observe that the directory has (again) been deleted locally:

enter image description here

Also, computer B is a cluster (I have little control/no sudo access). Perhaps they have some weird non-standard version of git or git settings on the cluster?

.gitignore contents:

$ cat .gitignore 
results.jld2
safe_to_graph
[redacted]_exit_results/
Environments/Recommender_Env/MSLR-WEB10K/*
!Environments/Recommender_Env/MSLR-WEB10K/csv_converter.py
!Environments/Recommender_Env/MSLR-WEB10K/pickle_file_checker.py
!Environments/Recommender_Env/MSLR-WEB10K/Fold1/
Environments/Recommender_Env/MSLR-WEB10K/Fold1/*
!Environments/Recommender_Env/MSLR-WEB10K/Fold1/vali_pickle
# Environments/Recommender_Env/Microsoft_Data_Set/.idea/
IJCAI_Async_Rec_results/
async_results/*
swarm_logs/*
zipresults/*
Environments/Recommender_Env/MQ2008/*
!Environments/Recommender_Env/MQ2008/csv_converter_MQ.py
!Environments/Recommender_Env/MQ2008/pickle_file_checker_MQ.py
!Environments/Recommender_Env/MQ2008/Fold1/
Environments/Recommender_Env/MQ2008/Fold1/*
!Environments/Recommender_Env/MQ2008/Fold1/vali_pickle
MUJOCO_LOG.TXT

Mureinik
  • 4,152

1 Answers1

2

Git doesn't delete local directories when you delete a file. When you apply a change (e.g., by doing git pull, git rebase or even git am), and that change removes all the files from the directory, it will also remove the directory.

I'd argue that if your program deletes/modifies files in a directory, this directory probably shouldn't be tracked at all, as it's ephemeral data, not a real part of your source code. I.e., here, it looks like the entire results directory should be under .gitignore.

Mureinik
  • 4,152