🛠️
Notes
  • README
  • ansible
    • Literal curly braces (raw)
  • bash
    • Case statement
    • Change quote style mid-string
    • Comparing versions
    • Hiding credentials on the command line
    • Directory of script
    • Using find to run a command on multiple files
    • Getting the line number of the nth match
    • Getopts
    • Parsing output with long lines using less
    • Print line at number
    • Remove final newline
    • Reading content between markers
    • Determine if a script was sourced or executed
    • Bash substring
    • Run a function on interrupt or error
    • Reference variable by name
  • chrome
    • Bypassing Chrome's NET::ERR_CERT_INVALID page
  • css
    • box-sizing: border-box
    • The currentColor keyword
    • Wrapper taking up at least 100% height
    • Using margin: auto; for centering
    • Margin-collapse
    • Which unit to use?
    • Hiding elements
  • git
    • Conditional git config includes
    • Viewing the evolution of a line or function
    • Name of current branch
    • Get the path to the repository root
    • Replaying a set of changes on a specific branch
    • Hide file from git diff output
    • Listing untracked files with git status
  • github
    • Setting up GitHub Actions
  • groovy
    • Appending items to a list
  • kubernetes
    • Waiting for a pod to be ready
  • make
    • Passing arguments to make rules
    • Running make in a set of subdirectories
  • npm
    • Update a value in a project's .npmrc
  • podman
    • Target last container
  • rust
    • The match operator
    • Unwrapping a Result
  • tmux
    • New window with prompt
  • tools
    • Running ngrok in the background
    • Using entr to react to file changes
  • typescript
    • Inferring the type of elements in an array
  • vim
    • The command-line window
    • Populate quickfix list with eslint errors
    • Visual increment
    • Opening a list of files in split windows
    • Insert line above matched line
    • Spelling
    • The tabular plugin
    • Populate quickfix list with tsc errors
  • yaml
    • Yaml multiline strings
  • zsh
    • Lazy loading command setup
Powered by GitBook
On this page
  • Line range
  • Function

Was this helpful?

  1. git

Viewing the evolution of a line or function

git log's -L flag allows us to trace the evolution of a single line, a range of lines, or a function.

Line range

To view the history of a range of lines, specify <start>:<end> following -L:

git log -L5,15:pom.xml

To view a single line, use the same line number for both <start> and <end>:

git log -L9,9:pom.xml

Function

To view the history of a function, specify :<funcname> following -L, where <funcname> is a regular expression.

git log -L:getUserById:path/to/my/Class.java

From the git-log manpage:

The function names are determined in the same way as git diff works out patch hunk headers

This is, by default:

... a line that begins with an alphabet, an underscore or a dollar sign

This won't be approriate in many cases, particularly not in Java where methods are members of classes, meaning they are indented. The default funcname regex does not match any lines with leading whitespace. To change how hunk headers are determined, we need to update .gitattributes within the project:

*.java  diff=java

We can define a custom regular expression that suits our purposes, but there are a few built-in patterns to make this easier, and java is one of them, so we're all set.

Source:

  • LESS='-p Defining a custom hunk-header' man gitattributes

  • LESS='-p -L<start>' man git-log

PreviousConditional git config includesNextName of current branch

Last updated 3 years ago

Was this helpful?