Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to only stash specific hunks (like patch)?

David Rees October 29, 2012

Is there a way to git stash just specific hunks? It seems to always take all files.

It would be nice that if the user could just stash the staged items (or the unstaged items - your choice). Essentially using the index as the input to --patch.

2 answers

3 votes
Philippe Fremy June 18, 2015

+1 from me as well. TortoiseHG allows to shelve (the equivalent of stash for mercurial) hunks and lines and it's very convenient.

I know it is already possible to commit only hunks or lines, but I want to only stage working code. The scenario that I am dealing with is the following :

  1. I want to add a new simple feature to my code.
  2. along with adding the feature I realise that I must modify a deep layer of the software and I go along
  3. I get everything to work (compile, unit-tests, functional tests) but now I have too many changes to commit, which are related to different areas of the code.
  4. From now on, I am desribing the workflow that I would like to have, not yet available in sourcetree.
  5. I want to commit first the changes in the deep layer of the code. I start an interactive stashing, stashing all the hunks not related to the deep layer of the code
  6. I now have only the changes related to the deep layer in my working copy. I compile, run unit-tests, run functional tests. I fix a typo here and there. 
  7. Everything works, I commit
  8. I restore my stash of the feature I was working on.
  9. I compile, run unit-tests, run functional tests.
  10. I commit my feature.

 

As you see, the important point is step 6 : I need to compile and run the exact code that I am checking in. This is not possible with hunk staging where you are staging something that is in practise not tested isolately.

 

1 vote
Dirk Weise October 13, 2014

+1. This would be very useful if you do a codechange unrelated to your current feature and want to keep it for later use.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events