0

Is there a way to unstage/revert single lines of changes using Git GUI? How can I do that?

enter image description here

I am a long time Atom user. Here I had the option to revert single lines or multiple selected lines of staged code as shown in the image:

enter image description here

Ohumeronen
  • 1,769
  • 2
  • 14
  • 28
  • Please do not delete this question since it is a question about: "software tools commonly used by programmers; and is" and "a practical, answerable problem that is unique to software development" According to: https://stackoverflow.com/help/on-topic – Ohumeronen Feb 26 '23 at 14:32
  • 1
    There's no point in asking people not to delete a question. Either it's a well written question and people will attempt to answer it, or its a question that is unclear or shows little research effort and it will get closed. The only way to prevent questions from being closed is to write good questions. – larsks Feb 26 '23 at 14:38
  • You are right but some of my questions have been closed and reopened in the past as they where perfectly valid. This should be the case with this question too as it is quite precise. – Ohumeronen Feb 26 '23 at 14:41
  • 1
    What does it mean "revert"? Revert to what state? What does it mean "revert single lines of changes" (single + plural "lines")? – phd Feb 27 '23 at 08:28
  • I edited the question according to your question. – Ohumeronen Feb 28 '23 at 10:35
  • "*Unstage Selection*" — i.e., checkout these lines from the last commit? – phd Feb 28 '23 at 10:40
  • To be honest, I do not know which git command the Atom editor uses. I want to do something like ```git reset -p``` but with single lines as shown in the image. I want to do this using Git GUI (preferrably) as I use this function a lot. – Ohumeronen Feb 28 '23 at 10:46
  • 1
    No such commands, neither in command-line `git` nor in Git GUI. Could be done manually with `git show HEAD:file > file.tmp` and copying lines from `file.tmp` to `file`. A lot of work, alas. Another solution is [`git add --interactive`](https://git-scm.com/docs/git-add#_interactive_mode), command `3: revert`. Also a lot of toil, not very convenient interface and only a partial solution — it can only revert a full hunk, not random lines. – phd Feb 28 '23 at 10:49
  • When you say "Git GUI", do you mean the tool that can be invoked with `git gui`? (This is different from the screenshot shown in the post.) – j6t Feb 28 '23 at 12:27
  • I added another image to make things clear. Yes, I mean "Git GUI". The second image is Atom, a tool I used in the past. – Ohumeronen Feb 28 '23 at 13:28

1 Answers1

0

Do you mean something like this : IntelliJ single line commit/revert

I never used Git GUI so I can't directly answer your question but some IDE have git plugin allowing you to select which line of change you want to commit or revert.

I guess you could also use a merge tool like kdiff3 or winMerge which have nice interface to select which part of the file you actually want to keep or not.

Edit :

Found this https://mfranc.com/blog/git-git-gui-staging-selected-lines/. I tried it on my side, if there are 2 lines as a block I cannot manage to push only one (but I have the same with my IDE). In the settings there is an option "number of diff context lines" that I though would solve the issue but I don't see the impact.

Kevin H.
  • 3
  • 4