Is there a way to git stash specific lines of a file?

You can stash specific lines from files by using the --patch option:

git stash --patch

git stash --patch  <filename>

Git will ask you interactively what you want to do with each file. You can edit the files or choose which lines get stashed

Note that you can also do this when adding files to your staging area with git add:

git add --patch  <filenames>

If what you want to do is commit part of a file, you can stage the part you want to commit with git add --patch, and there is no need to stash.


Read about git branches, which allow you to work on fixes to multiple aspects of a project separately.

You should create one branch for the big ongoing changes, and a separate branch for the smaller update.

Example with more details: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Tags:

Git