Skip to content
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

Add ability to revert single files/hunks/lines #7

Closed
deathaxe opened this issue Sep 27, 2018 · 7 comments
Closed

Add ability to revert single files/hunks/lines #7

deathaxe opened this issue Sep 27, 2018 · 7 comments
Labels
enhancement New feature or request

Comments

@deathaxe
Copy link

Problem description

If a bug was found being introduced by a commit, it might be useful to be able to revert the causing file, hunk or even just a single line of code. This can be required as a temporary solution until a better fix is available or to remove a regression. It would at least help complete all functions like (stage/stash/revert/...) supporting all kinds of operation in the same way.

Preferred solution

The command should work like staging files. Means select single folders, files, hunks or lines to revert.

The hunk header of a committed file currently just shows the "hunk history" button. Maybe the hunk header could be turned into a toolbar containing things like

  • Revert Hunk
  • etc.

Selecting single lines within the hunk should then change the buttons to

  • Revert Lines
  • etc.

The commands should be able to be bound to user defined keys as well.

Such a toolbar could make use of glyphs/icons instead of text to keep the button size as compact as possible. A description of the action can be displayed as tooltip if the button is hovered. The buttons might be hidden in the same way as the current "hunk history" button.

@wbond wbond added the enhancement New feature or request label Sep 27, 2018
@hstormo
Copy link

hstormo commented Jan 13, 2019

Here's a way to at least check out files:

[
    { "caption": "-" },
    {
        "caption": "Reset file to this version",
        "command": "git",
        "args": {"argv": ["checkout", "$commit", "$path"]}
    }
]

Save in your user folder as File.sublime-menu.

@shawjef3
Copy link

shawjef3 commented May 7, 2019

Reversing/reverting hunks and selected lines are the only features keeping me from switching from SourceTree.

@srbs
Copy link

srbs commented Jun 5, 2019

Workaround for reverse hunk:
https://forum.sublimetext.com/t/reverse-hunk-workaround/44645

@kakra
Copy link

kakra commented Nov 19, 2019

Isn't this usually a problem of having committed unrelated changes within the same commit previously? If a hunk could work on it's own it should have been committed as a single commit in the first place... While it may come in handy, it may promote not committing atomic changes.

If you need to revert a hunk, you should probably revert the complete commit without yet committing it, then only stage the hunks that need to be reverted, commit, then discard the rest.

So I think it could be useful to have a context menu item "Revert without committing" aka git revert --no-commit. That way, you could either squash multiple reverts into one, or stage just one reverting hunk and discard the rest.

@deathaxe
Copy link
Author

Isn't this usually a problem of having committed unrelated changes within the same commit previously?

No. What if you made a fix for an issue which containes many code lines. During review another guy finds a regression in maybe one or two lines, which he wants to revert.

This might not be an everyday scenario, but I was sometimes faced to it here and there.

If you need to revert a hunk, you should probably revert the complete commit without yet committing it, then only stage the hunks that need to be reverted, commit, then discard the rest.

  1. Of course, you can always take the long way - or the sublime one.
  2. This PR was made with the functionality of GitExtensions in mind and to make all git related functions (stash,stage,revert) work the same way on all pieces of code.

@srbs
Copy link

srbs commented Jul 17, 2020

This has been added in dev build 2024!

@deathaxe
Copy link
Author

Nice job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants