• Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • None
    • None
    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

      There is a workaround for stashing only selected files, but it is awkward:
      https://community.atlassian.com/t5/Sourcetree-questions/Stashing-selected-files/qaq-p/137139

      I frequently find myself wanting to commit portions of what I'm working on to a different branch. Being able to divide my uncommitted changes into different stashes so I can apply them to the desired branches would be very helpful. Example: I'm in the middle of working some one big feature when a simple bug is reported. I fix the bug in the development environment, test, and want to commit that one change to the released branch and push to staging/production.

      Thank you for an awesome product.

            [SRCTREEWIN-9103] Support stashing selected files only

            Mukesh Kumar added a comment -

            This feature has been implemented and will be available in Sourcetree 3.4.24 onwards.

            Mukesh Kumar added a comment - This feature has been implemented and will be available in Sourcetree 3.4.24 onwards.

            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.

            Joshua Armour added a comment - 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.

            698877135425 is this still being worked? I would use this frequently if it were available in SourceTree! 

            Aaron Lawrence added a comment - 698877135425 is this still being worked? I would use this frequently if it were available in SourceTree! 

            We are working on this feature.

            Mukesh Kumar added a comment - We are working on this feature.

            zsolt.szkocsovszki added a comment - - edited

            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.

            zsolt.szkocsovszki added a comment - - edited 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.

            Make sure you actually browse to the full path of git.exe for "Script to run"; don't just enter the text "git.exe" 

            You can find out what the path is by Tools > Options > Git tab > bottom area called "Git Version"

            Shola Omojokun added a comment - Make sure you actually browse to the full path of git.exe for "Script to run"; don't just enter the text "git.exe"  You can find out what the path is by Tools > Options > Git tab > bottom area called "Git Version"

            This workaround does not work for me. Here is the output:

            git stash push <cut out filenames>
            Completed with errors, see above.

            What errors above?

            Peter Franklin added a comment - This workaround does not work for me. Here is the output: git stash push <cut out filenames> Completed with errors, see above. What errors above?

            @bablex Thanks for the workaround! I personally like to also include the file name in the stash so that I can understand the stash list without looking at whats stashed there via the message option: 

            stash push $FILE --keep-index --message $FILE
            

            For anyone seeing this issue, it might be helpful to consult the git stash docs to see which parameters are available.

            Sascha Mayr added a comment - @bablex Thanks for the workaround! I personally like to also include the file name in the stash so that I can understand the stash list without looking at whats stashed there via the message option:  stash push $FILE --keep-index --message $FILE For anyone seeing this issue, it might be helpful to consult the git stash docs  to see which parameters are available.

            If we use the Custom Action solution above (which does work), then is there any way to name (or rename) the stash?

            Seems like this would be a very useful feature!

            Ron MacCracken added a comment - If we use the Custom Action solution above (which does work), then is there any way to name (or rename) the stash? Seems like this would be a very useful feature!

            @L go to Tools > Options
            Select the Custom Actions tab.

            Andrew Wietecha added a comment - @L go to Tools > Options Select the Custom Actions tab.

            L added a comment - - edited

            Can't see the image but yeah it doesn't exists for me. And yes its windows10.

            menu

            L added a comment - - edited Can't see the image but yeah it doesn't exists for me. And yes its windows10. menu

            bablex added a comment -

            @L this doesn't exist for you? Are you on Windows?

            bablex added a comment - @L this doesn't exist for you? Are you on Windows?

            L added a comment - - edited

            @bablex Thanks - this is a good workaround!

            Small addition though:

            Tools => Options => Custom Actions => Add

            Then just select the files you want to stash (hold ctrl to select multiple).
            Right click on any file => Custom Actions => Stash selected files

            This doesn't work for me (might be a bug in the latest version?) - there is no submenu of "Custom actions" if I right click. For this I have to go into the  menu

            Actions => Custom Actions => Stash selected files

             

            L added a comment - - edited @bablex Thanks - this is a good workaround! Small addition though: Tools => Options => Custom Actions => Add Then just select the files you want to stash (hold ctrl to select multiple). Right click on any file => Custom Actions => Stash selected files This doesn't work for me (might be a bug in the latest version?) - there is no submenu of "Custom actions" if I right click. For this I have to go into the  menu Actions => Custom Actions => Stash selected files  

            bablex added a comment -

            There is actually a simple workaround for this.
            Tools => Custom Actions => Add

            "Menu caption": Stash selected files
            Uncheck all checkboxes EXCEPT "Run command silently"
            "Script to run": git.exe
            "Parameters": stash push $FILE
            (if you want to keep staged changes, add  --keep-index to parameters)

            Then just select the files you want to stash (hold ctrl to select multiple).
            Right click on any file => Custom Actions => Stash selected files

            Now it will only stash the selected files.

            bablex added a comment - There is actually a simple workaround for this. Tools => Custom Actions => Add "Menu caption": Stash selected files Uncheck all checkboxes EXCEPT "Run command silently" "Script to run": git.exe "Parameters": stash push $FILE (if you want to keep staged changes, add  --keep-index to parameters) Then just select the files you want to stash (hold ctrl to select multiple). Right click on any file => Custom Actions => Stash selected files Now it will only stash the selected files.

            L added a comment -

            It would be really helpful if this feature gets implemented. Thanks guys...

            L added a comment - It would be really helpful if this feature gets implemented. Thanks guys...

              698877135425 Mukesh Kumar
              f16097ef1d44 danchadwick
              Votes:
              127 Vote for this issue
              Watchers:
              47 Start watching this issue

                Created:
                Updated: