简体   繁体   中英

Restore files on git that were deleted when a branch was deleted

I know there are a lot of similar questions on SO about this topic, so I apologize if this is a duplicate. However, I think this case is unique compared to the others I've seen.

I had some local files in my repo directory which I did not realize were untracked. I then created a new local branch, made a significant change to the directory structure, and did a git add of the entire directory and committed (this was the most convenient way I could think of to commit the restructure).

I later changed my mind about the restructure, so I deleted the entire branch without merging it, but this unfortunately deleted all the previously untracked files which weren't present in any of the other branches.

I was able to find commits from the deleted branch and check them out, but the deleted files are nowhere to be found. I've also tried using:

 git log -- <filepath>

Unfortunately that's not showing anything either. These files were definitely deleted when the branch was deleted, so they must have been tracked by git at some point, but I can't find anything at all.

If the file was truly committed, and your reflog was not deleted (by default - 30 days), you should be able to see which commits affected a particular set of files or directories by one the following:

git reflog -- path/to/some/file.txt
git reflog -- path/to/some/file.txt path/to/another/file.txt
git reflog -- path/to/some/directory
git reflog -- */some.file 

If it does not show up, then it means that it was never added to a commit.

If it was possibly stashed, then the following command can help:

git stash list -- path/to/some/file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM