I have a directory tree in my repo. I do a git add -A first time.
Now I remove a directory with files by mistake and do a:
git add -A
I lose the entire directory in my repo too. Or is there a way to retrieve my lost directory?
Also suppose I do a git add . I wouldn’t have lost my directory, am I correct?
So I take it there is no way to track deletion of files using git?
For example I deleted 3 files when I did an commit yesterday and if I want to go back to yesterday’s version of all files and directories would I see the deleted files?
My understanding of your question is this:
gitrepository with some files and directories.git add -A). Presumably you’ve also committed.rm -rf dir), then add the changes (git add -A). I assume you then commit.If this is the case, then yes, you’ve removed the directory from the repository. From the
git-addman page:git add -Awill add all changes to the repository – additions, removals, the lot.I’m unsure what you mean by this. You can track deletion of files from git. Read the man-page for
git-rm. Or, delete a file, then rungit add -A:gitwill add the deleted file to the index, allowing you to commit the deletion. So the deletion is tracked.You wouldn’t have staged the deletion of the directory to the
gitindex, correct. The directory is still gone from thegitworking directory, though, because you deleted it.You add a file to your repository.
git add file; git commit -m "added file". Let’s call this commitA.Next you delete that file, and commit the change to the repository:
rm file; git add -A; git commit -m "Deleted file"(another way isgit rm file). Let’s call this commitB.If you checkout commit
B, the files are not there. You deleted them, and the commit reflects this.If you checkout commit
A, the files are there. That commit contains the files.To answer your question:
No. You won’t see the files in yesterdays commit, because you’ve committed the deletion. If you checkout the commit before yesterdays commit, though, the files are there.