How can I use git to stage only one line in a file for commit, all from a script?
- by Sandy
I'm writing a simple pre-commit git hook that updates the year in copyright headers for files that are staged for commit.
After modifying the line with the copyright, I would like the hook to stage that line so that it is part of the commit. It can't just git add the whole file, because there may be other pre-existing changes in there that shouldn't be staged.
I don't see any options in the git add manual the let you stage specific lines.
I figure I could git stash save --keep-index, apply my change, git add the file, and then git stash pop, but that seems rather crude. Any better approaches?