I want to get back some code that I deleted in some commit some time ago. I don't remember what the code was at all, but I remembered that it did something very useful, but I deleted it because I thought I wouldn't need it. However, I now need that code back, but I only remember what function it was in.
Other information: the file containing that function also contains 500 lines of code total. There is a 30 commit range I know that the code appeared in at one point.
This question is a high level problem. How can I use the information I know to get the information I want?
The best you can do is with search keywords. If you know a function name
git log -Sfunction
would be perfect.
If you have a pattern you can look for in each commit's changes:
git log --grep=pattern
Will list commits containing that pattern. Add -i
for case insensitive match. Add --regex
for regular expression match
Otherwise
git log -p FIRST...LAST | less
will give you full text. You could search, or just scroll and visually scan...
Oh. PS. Since you mention it is a long function, you could just do
git log --stat FIRST...LAST
And watch for files with many deletions (----
) in the diff stats.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With