Is it possible to git-checkout a single line instead of the entire file?

LuisVM picture LuisVM · Aug 6, 2011 · Viewed 15.7k times · Source

If I have modified several lines of a versioned file, is it possible to undo the changes of a line by command-line?

Just like I would do for an entire file with:

git checkout /path/to/file.extension

but doing something like, say

git checkout /path/to/file.extension --line 10

is this possible?

Answer

Matt Enright picture Matt Enright · Aug 6, 2011

You can use git checkout -p to see each hunk individually and decide whether to check them out or leave them as is (and that takes an optional path argument as well if you'd like to narrow it down further).