If you have multiple files with changes and you want to stash only one specific file while keeping the others, you can use the git stash
command along with the path of the file you want to stash. Here's how you can do it:
sh
git stash push -m "Stash message" path/to/your/file
Let's go through an example:
Suppose you have three files with changes: file1.txt
, file2.txt
, and file3.txt
. You want to stash only the changes in file2.txt
.
Make Changes to Files:
Create or modify the three files.
sh
echo "Change 1" > file1.txt
echo "Change 2" > file2.txt
echo "Change 3" > file3.txt
Stash a Specific File:
To stash only the changes in file2.txt
, use the following command:
sh
git stash push -m "Stash only file2.txt changes" file2.txt
Verify Stash:
You can verify that only the changes in file2.txt
were stashed using git stash list
:
sh
git stash list
The output will show your stashed changes, including the message you provided in -m
.
Restore the Stash:
If you want to restore the stashed changes later, you can use the following command:
sh
git stash apply stash@{0}
This will apply the stashed changes back to the working directory.
By specifying the path to the file you want to stash, you can selectively stash specific changes while keeping others.
Comments
Post a Comment