Let's say I have files A, B, C, D in my repo. All of them has been modified from the last commit, but not staged yet. Due to a syncing bug, A and B are deleted. I understand that changes in them are gone, but at least I want to recover them from the last commit. Is there a way to git reset --hard only deleted files while keeping existing files intact? Assuming there are many of them, so I can't git checkout individual files or folders.
How to git reset --hard only deleted files and keep existing files intact?
109 views Asked by Ooker At
1
Instead of a
git reset --hard, agit ls-files -dmight help (coupled withgit restore, if you are using Git 2.23+):For listing deleted files from a given commit, you would use
git logwith adiff-filter, and an empty format:In your case, to restore those files from that commit:
Or, as LeGEC mentions in the comments, using the same
diff-filterwithgit diff: