Search code examples
gitgit-workflow

Git - get given range of lines from given file from given branch


I wonder if it's already possible to get given range of lines from given file from given branch in GIT? I'm working on pretty big project, reloading whole solution after switching to a new branch lasts a few seconds, but sometimes I need to see the history / version of current file from e.g. master. Is it possible without switching to master?


Solution

  • You can use cat-file to print the content:

    git cat-file blob feature/my-feature:./README
    

    And then pass to for example sed to get the line range:

    git cat-file ... | sed -n '10,20p'