New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow to Stash by line, not just by Hunk #413

Closed
ovidiub13 opened this Issue Feb 9, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@ovidiub13

ovidiub13 commented Feb 9, 2015

This feature exists in git gui, would be nice to also have here.

@davvid

This comment has been minimized.

Member

davvid commented Feb 10, 2015

Interesting, I'll have to take a look at how it's done there. Right now you can get this feature by staging the parts you want to keep in your worktree, and then use "stash" with the "keep index" option.

That'll keep the stuff you've staged and the unstaged stuff will get stashed.

@darkvertex

This comment has been minimized.

darkvertex commented Sep 19, 2016

I realise this is over a year old, but how exactly do you "stash by hunk" from git-cola?

@davvid

This comment has been minimized.

Member

davvid commented Sep 21, 2016

The analog is command-line git's "Testing partial commits" from git help stash:

       Testing partial commits
           You can use git stash save --keep-index when you want to make two or more commits out of the changes in the work tree,
           and you want to test each change before committing:

               # ... hack hack hack ...
               $ git add --patch foo            # add just first part to the index
               $ git stash save --keep-index    # save all other changes to the stash
               $ edit/build/test first part
               $ git commit -m 'First part'     # commit fully tested change
               $ git stash pop                  # prepare to work on all other changes
               # ... repeat above five steps until one commit remains ...
               $ edit/build/test remaining parts
               $ git commit foo -m 'Remaining parts'

The "stash by line" thing is "add just first part to index". Basically, you stage the parts that you don't want stashed, and then stash with the "Keep Index" option checked in the stash dialog to do the "save all other changes to the stash" step.

Semantically, it's the inverse because we choose what you don't want to stash rather than what you want to stash, but we can accomplish the same end result.

The diff editor lets you stash by line. Select just the lines you want to keep (I usually just select a small unique subset in the line, it doesn't need to be the full line) and then hit "s" to stage the selected lines.


That said..

It would be kinda nice if git stash itself had an --index option that basically took the staged contents and stashed it away. It would basically be the mirror image of --keep-index's behavior, and would be the base upon which we could base this feature.

If you don't mind, want to bring this up on the Git mailing list? If there's consensus there that we can add a new option to git stash to make it behave this way then we can start there. If they'd rather not take such a patch, then we can implement the feature in cola, it actually shouldn't be too hard.

What do you think? Is the current inverse workflow good enough, or should we add a knob to git stash?

@davvid

This comment has been minimized.

Member

davvid commented Mar 4, 2018

BTW I looked at git-gui and I couldn't find this feature. I don't think it exists -- the only feature it has is line-by-line staging, which we already have (cola's feature actually predates the one in git-gui). In any case, we'll probably get this feature first too (please test the forthcoming commit)

davvid added a commit to davvid/git-cola that referenced this issue Mar 4, 2018

gitcmds: add rev_parse()
Related-to: git-cola#413
Signed-off-by: David Aguilar <davvid@gmail.com>

davvid added a commit to davvid/git-cola that referenced this issue Mar 4, 2018

stash: add a StashIndex command
Add a command to stash staged changes.  This allows users to selectively
stash changes line-by-line by leveraging the existing index editor.

Related-to: git-cola#413
Signed-off-by: David Aguilar <davvid@gmail.com>

davvid added a commit to davvid/git-cola that referenced this issue Mar 4, 2018

stash: add tooltips and tweak style
Related-to: git-cola#413
Signed-off-by: David Aguilar <davvid@gmail.com>

davvid added a commit to davvid/git-cola that referenced this issue Mar 4, 2018

Merge branch 'stash'
Teach the stash tool to stash staged changes only.

* stash:
  stash: add a "Stash Index" option to stash staged changes only
  stash: add tooltips and tweak style
  stash: add a StashIndex command
  stash: make the command classes DRY
  gitcmds: add rev_parse()
  qtutils: add connect_checkbox()

Closes git-cola#413
Signed-off-by: David Aguilar <davvid@gmail.com>

@davvid davvid closed this in 9526899 Mar 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment