Alex Bollbach
Alex Bollbach

Reputation: 4570

Git: Is there a way to show a subset of lines from a revision?

How can I view a subset of lines from a file in some previous commit. Normally I do git show HEAD:path/to/file but if I'm only interested in a particular area of code I'd like to be able to say, e.g.git show HEAD:path/to/someFile 33-47 which would show the state of someFile at the current HEAD for those lines only.

Upvotes: 1

Views: 34

Answers (2)

jpkotta
jpkotta

Reputation: 9417

git show HEAD:path/to/someFile | tail -n +33 | head -n $((47-33+1))

@ElpieKay provides a cleaner solution with sed:

git show HEAD:path/to/someFile | sed -n 33,47p

Upvotes: 3

ElpieKay
ElpieKay

Reputation: 30868

git blame <revision> -L 33,47 <path>

Upvotes: 2

Related Questions