简体   繁体   中英

Git | Restore Unadded Files At Commits Times

TL;DR: I didn't add files, pushed updates and now I can't see the files in previous commits - I want to restore them.

What happened: When I committed one time, I forgot to add them to the index, and then reverted back to a previous commit.

Is there a way to restore those files, via a diff or something? When git tries to commit while there are unadded files in the repository, what happens to those files? Does Git save information about them anywhere? Does it save them anywhere? Does it completely delete them?

I'm working on Visual Studio code and I've got GitLens, in case they can be of use.

Update: I think that I found that those untracked files were saved as either dangling blobs or unreachable objects. I'm currently checking this direction.

Found a solution:

*Note: this does not restore file names.

  1. Use git fsck --unreachable to get a list of all unreachable objects which displays for each object their SHA-1 ID.
  2. For each object: use git show <SHA-1 ID> to read the contents of each object.
  3. For each object: save the contents of the desired object into a file. Optional: try to guess the name of the file based on its contents.

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