Reputation: 151
I have a repository that belongs only to me but allows me to manage a project across multiple machines with versioning. Somehow, at some point I committed in such a way that some important includes were deleted, but I did not notice until I needed them today. So I am trying to figure out how to take the versions of those files from the last commit where I know they are correct and pull them into the current master. There are a couple of questions on here that seem like they should answer this, but the answers seem to be describing something else.
I can check out from the correct commit and I read about rebasing, but I am hesitant to do anything without asking those with more experience.
Upvotes: 2
Views: 54
Reputation: 59963
You can use git checkout
to put back the deleted files into your working directory.
Assuming you already know which commit deleted the files, you can say:
git checkout <commit-ish>^ -- <deleted-path>
where:
commit-ish
is a reference to the commit in question^
references that commit's parentdeleted-path
is the path of the file or directory that you want to restoreFor example, assuming a12b34
is the SHA-1 of the commit that deleted the foo
directory, you would say:
git checkout a12b34^ -- path/to/foo
In short, this commands tells Git to get the files in the specified path as they were before the commit that deleted them, and put them back in the working directory.
Upvotes: 1
Reputation: 9908
git log --summary --diff-filter=D
Let's say you find out the exact commit hash as abcde12345
where this important file was deleted.
git checkout $commit~1 path/to/file.ext
Where $commit is the value of the commit you've found abcde12345
Upvotes: 1