• Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • None
    • Beta
    • 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.

      It would be a nice feature the possibility of stash only the staged files and not all the uncomitted files

            [SRCTREEWIN-5714] Stash only staged files

            We are working on it.

            Mukesh Kumar added a comment - We are working on it.

            This should be fairly easy to implement since `git stash` now supports the `–staged` argument: https://git-scm.com/docs/git-stash#Documentation/git-stash.txt---staged

            Rutger Hertogh added a comment - This should be fairly easy to implement since `git stash` now supports the `–staged` argument: https://git-scm.com/docs/git-stash#Documentation/git-stash.txt---staged

            Joseph Dunne added a comment - - edited

            Honestly I haven't used this script recently, but it appears I did some modifications to it since the original version I posted.  Here's my latest version.  I'm not sure if this will resolve the issue you're seeing though.  I suspect the bashruncmd.bat was the solution to what you described.

             

            Edit: I also modified the custom action in SourceTree.  It should look like this:

             

            Script to Run:  C:\git\tools\bashRuncmd.bat

            Parameters: c:\git\tools\Stash_Staged.sh $REPO

             

            Here's my bashruncmd.bat file:

             

            SET mypath=%~dp0
            start "C:\Program Files\Git\git-bash.exe" %1 %2 %3 %4 %5
            

             

             

            And the updated Stash_Staged.sh script:

            #!/bin/bash#!/bin/bash
            #This script stashes only the staged changes.
            #note when setting variables in bash you cannot have spaces:rootpath=$PWD
            echo $1
            #echo rootpath: $rootpath
            thisscriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
            #echo thisscriptpath: $thisscriptpath
            myargs=$'"Enter a message to describe the stash (cannot be empty): "'
            tmpfile=$(mktemp)wscript.exe "$thisscriptpath\inputbox.vbs" $myargs >$tmpfileif [ $? -eq 0 ]then echo "User Clicked OK."else echo "User Clicked Cancel or closed the dialog." exit 1fi
            InputBoxText=$(<$tmpfile)
            echo InputBoxText: $InputBoxText
            #After this multi stage process, any staged files will be stashed and unstaged files will remain.
            #Stash everything temporarily.  Keep staged files, discard everything else after stashing.git stash --keep-index
            #Stash everything that remains (only the staged files should remain)  This is the stash we want to keep, so give it a name.git stash save "$InputBoxText"
            #Apply the original stash to get us back to where we started.git stash apply stash@{1}
            #Create a temporary patch to reverse the originally staged changes and apply itgit stash show -p stash@{0} | git apply -R
            #Delete the temporary stashgit stash drop stash@{1}
             
            

             

             

             

            Joseph Dunne added a comment - - edited Honestly I haven't used this script recently, but it appears I did some modifications to it since the original version I posted.  Here's my latest version.  I'm not sure if this will resolve the issue you're seeing though.  I suspect the bashruncmd.bat was the solution to what you described.   Edit: I also modified the custom action in SourceTree.  It should look like this:   Script to Run:  C:\git\tools\bashRuncmd.bat Parameters: c:\git\tools\Stash_Staged.sh $REPO   Here's my bashruncmd.bat file:   SET mypath=%~dp0 start "C:\Program Files\Git\git-bash.exe" %1 %2 %3 %4 %5     And the updated Stash_Staged.sh script: #!/bin/bash#!/bin/bash #This script stashes only the staged changes. #note when setting variables in bash you cannot have spaces:rootpath=$PWD echo $1 #echo rootpath: $rootpath thisscriptpath= "$( cd " $( dirname "${BASH_SOURCE[0]}" ) " && pwd )" #echo thisscriptpath: $thisscriptpath myargs=$ ' "Enter a message to describe the stash (cannot be empty): " ' tmpfile=$(mktemp)wscript.exe "$thisscriptpath\inputbox.vbs" $myargs >$tmpfileif [ $? -eq 0 ]then echo "User Clicked OK." else echo "User Clicked Cancel or closed the dialog." exit 1fi InputBoxText=$(<$tmpfile) echo InputBoxText: $InputBoxText #After this multi stage process, any staged files will be stashed and unstaged files will remain. #Stash everything temporarily.  Keep staged files, discard everything else after stashing.git stash --keep-index #Stash everything that remains (only the staged files should remain)  This is the stash we want to keep, so give it a name.git stash save "$InputBoxText" #Apply the original stash to get us back to where we started.git stash apply stash@{1} #Create a temporary patch to reverse the originally staged changes and apply itgit stash show -p stash@{0} | git apply -R #Delete the temporary stashgit stash drop stash@{1}        

            Code Owl added a comment -

            @Nicola Spreafico,

            Thanks for the response mate.  Yes I am on windows 10 64bit too.  I can execute the vbs directly from the cmd prompt, but it does not seem to get executed by the sh file.

             

            @Joseph Dunne, any ideas on what the issue might be mate?  Did you update it to work on Windows 10 with the latest SourceTree?

             

            Thanks for your time.

            Code Owl added a comment - @Nicola Spreafico, Thanks for the response mate.  Yes I am on windows 10 64bit too.  I can execute the vbs directly from the cmd prompt, but it does not seem to get executed by the sh file.   @Joseph Dunne, any ideas on what the issue might be mate?  Did you update it to work on Windows 10 with the latest SourceTree?   Thanks for your time.

            Nicola Spreafico added a comment - - edited

            Hello @Scotty,

            I haven't tried this function in a while, but not that you're telling me I can see that it does not work anymore. Maybe is something related to Windows 10 and its permissions on executing .vbs file (Windows 10 in my case).

             

            We should ask the original author of the .vbs file.

            Nicola Spreafico added a comment - - edited Hello @Scotty, I haven't tried this function in a while, but not that you're telling me I can see that it does not work anymore. Maybe is something related to Windows 10 and its permissions on executing .vbs file (Windows 10 in my case).   We should ask the original author of the .vbs file.

            slaughton added a comment -

            @Nicola Spreafico,

            Thanks for taking the time to share this solution.  I am attempting to get this working in SourceTree 3.0.15.  The messagebox does not show and SourceTree says Completed successfully, but not the Stash does not appear under the Stashes node in SourceTree UI.

            Did you have an updated version of this that worked with the latest SourceTree?

            Thanks for your time.

             

            slaughton added a comment - @Nicola Spreafico, Thanks for taking the time to share this solution.  I am attempting to get this working in SourceTree 3.0.15.  The messagebox does not show and SourceTree says Completed successfully, but not the Stash does not appear under the Stashes node in SourceTree UI. Did you have an updated version of this that worked with the latest SourceTree? Thanks for your time.  

            I'm using 1.9.7.2-beta2 version, maybe they have changed something during the beta stage.
            But I don't worry about this, I can use it from the main menu as well.

            Thank you for the keep stashed changes hint.

            Nicola Spreafico added a comment - I'm using 1.9.7.2-beta2 version, maybe they have changed something during the beta stage. But I don't worry about this, I can use it from the main menu as well. Thank you for the keep stashed changes hint.

            I'm not seeing that issue. I'm able to right click in the stage area and select Custom Actions > (action name) and it works just fine. I'm running SourceTree v1.9.6.1. Maybe you have an older version?

            As for keeping the stashed changes, simply remove the line that undoes them... (Or even have 2 copies of the script, one that keeps the changes and one that doesn't)
            Comment this line:
            git stash show -p | git apply -R

            Joseph Dunne added a comment - I'm not seeing that issue. I'm able to right click in the stage area and select Custom Actions > (action name) and it works just fine. I'm running SourceTree v1.9.6.1. Maybe you have an older version? As for keeping the stashed changes, simply remove the line that undoes them... (Or even have 2 copies of the script, one that keeps the changes and one that doesn't) Comment this line: git stash show -p | git apply -R

            Nicola Spreafico added a comment - - edited

            Now works perfectly, thank you very much.
            From Actions > Custom Actions > (action name) works fine

            Right-clicking on the Stage area and selecting Custom Actions > (action name) does not work (the commits list is is simply refreshed).
            But I think this is related to SourceTree interface.

            A question though: how about choosing if keeping stashed changes? Like the default Stash option.

            Nicola Spreafico added a comment - - edited Now works perfectly, thank you very much. From Actions > Custom Actions > (action name) works fine Right-clicking on the Stage area and selecting Custom Actions > (action name) does not work (the commits list is is simply refreshed). But I think this is related to SourceTree interface. A question though: how about choosing if keeping stashed changes? Like the default Stash option.

            I added the InputBox.vbs. Sorry about that. I hope it works out well for you.

            Joseph Dunne added a comment - I added the InputBox.vbs. Sorry about that. I hope it works out well for you.

              698877135425 Mukesh Kumar
              803677bd570e Nicola Spreafico
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated: