I created a batch script to stash the selected files only. With this solution you can also provide a message for the stash entry.
@echo off
REM Create a temporary file for entering the stash message
set "input_file=stash_message.txt"
REM Open the file with Notepad
start notepad "%input_file%"
REM Wait until the file is saved and closed
powershell -Command "while ((Get-Process notepad -ErrorAction SilentlyContinue) -ne $null) { Start-Sleep -Milliseconds 500 }"
REM Read the content of the file into a variable
for /f "usebackq delims=" %%a in ("%input_file%") do (
set "stash_message=%%a"
)
REM Delete the temporary file
del "%input_file%"
REM Initialize variable for the selected files
set "selected_files="
REM Concatenate every argument using a space as delimiter
:concatenate
if "%~1" neq "" (
if defined selected_files (
set "selected_files=%selected_files% %~1"
) else (
set "selected_files=%~1"
)
shift
goto :concatenate
)
REM Stash the selected files with the provided stash message
git stash push %selected_files% -m "%stash_message%"
After you created such a .bat file, add it as a custom action in the following way:
1. Give an arbitrary name for the custom action in the "Menu caption" field.
2. Only "Run command silently" has to be checked.
3. Browse for the created .bat file in the "Script to run" section.
4. Set the "Parameters" to $FILE.
After you selected all the files that you want to stash and clicked the custom action, a text file will open where you can provide the message. Write the message in this file, save it and then close it. The selected files will be stashed with the provided message.
Neither of these solutions in the comments work if you want to stash multiple files that have a space in the directory name... Does anyone have a solution? putting "$FILE" in quotes works for one file but not multiple.