GitHub recover deleted blocks of code

I am working on a project and we have a file where a few blocks of code that go together were deleted at different intervals a few commits back. I need to recover only some of these blocks and put them into something else I’m making. Is there a way to see the old blocks that were committed and copy them without having all the junk before/around the lines (like when you look at it with Git Extensions or GitHub. I basically just want to be able to grab some old code blocks manually for use in another project that isn’t on the repository.

Thanks

  • What does the word TREESAME mean in the context of git?
  • How can I disregard new files added to the git?
  • Git/gitosis: How to check validity of user name and email?
  • OpenCV 3.0.0 make error with FFMPEG
  • How do I host a Jekyll blog on a github subdirectory?
  • git track binary files but ignore content?
  • LaTeX math in github wikis
  • GitLab: You are not allowed to access master! After moving gitlab to another server
  • Can you clone an OpenShift application repo via HTTPS instead of SSH?
  • Where to manage the most sensitive content you have under version control?
  • Is there a way to 'script' a git commit - only accepting some diffs?
  • git-new-workdir: Commit in working tree A causes bogus changes in tree B
  • 2 Solutions collect form web for “GitHub recover deleted blocks of code”

    The general idea would be to:

    • use git log -SFoo -- path_containing_change in order to detect commits where you have added or, more importantly, removed a certain line: see “How to grep (search) committed code in the git history?”. git grep <regexp> $(git rev-list --all) can also help (can be slower though)

    • for each relevant commits, make a patch for the right files (as in ““git format-patch” equivalent for a single file?”)

    • apply those patches to your other repo project.

    In github you can view the list of commits, simply click “view code” next to the commit where this code still exists. Then you can browse to the files that contains the code you want and click “raw” to see the file without “having all the junk”.

    Git Baby is a git and github fan, let's start git clone.