In this article you learn how to stash only one file out of multiple files that are changed?
To stash only one file out of multiple files that have changed, you can use the "git stash
" command with the "--keep-index
" option. This will allow you to stash only the changes you do not want to keep in the working directory.
Then you can use the command "git reset <file>
" where file is the file you want to keep in your working directory.
For example, if you have multiple files named "file1.txt", "file2.txt", "file3.txt" and you want to stash changes to "file1.txt" and "file2.txt" but keep "file3.txt" in your working directory, you would run the following commands:
git stash save --keep-index
git reset file3.txt
This will stash the changes to "file1.txt" and "file2.txt" and leave "file3.txt" in your working directory.
You can then use "git stash list
" command to see the stashed changes and use "git stash apply
" command to apply them again or "git stash drop" to delete the stash.
It's important to note that, this will stash the changes to the file in the current branch only, if you switch to another branch, the stashed changes will not be available.
The git stash
command shelves changes made to the working copy so you can do another work, and then return and re-apply them. The command will stash the changes that have been added to your index (staged changes) and changes made to files currently tracked by Git (unstaged change. The --keep-index
option left intact all the changes that are already added to the index.