* How to commit hunks using VC?
@ 2018-10-26 13:26 Diogo F. S. Ramos
2018-10-26 14:34 ` Dan Čermák
2018-10-26 15:56 ` Stefan Monnier
0 siblings, 2 replies; 17+ messages in thread
From: Diogo F. S. Ramos @ 2018-10-26 13:26 UTC (permalink / raw)
To: help-gnu-emacs
Is it possible to commit only some hunks using VC?
When using VC with git as a backend, sometimes I want to commit only a
few hunks from different files. Usually I go to a shell and issue `git
add -p' to select different hunks, but can I do it from VC? Maybe from
the diff buffer?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 13:26 How to commit hunks using VC? Diogo F. S. Ramos
@ 2018-10-26 14:34 ` Dan Čermák
2018-10-26 15:56 ` Stefan Monnier
1 sibling, 0 replies; 17+ messages in thread
From: Dan Čermák @ 2018-10-26 14:34 UTC (permalink / raw)
To: help-gnu-emacs
Not sure if it is possible from VC, but magit can do that via a very
nice (diff-like) interface.
"Diogo F. S. Ramos" <dfsr@riseup.net> writes:
> Is it possible to commit only some hunks using VC?
>
> When using VC with git as a backend, sometimes I want to commit only a
> few hunks from different files. Usually I go to a shell and issue `git
> add -p' to select different hunks, but can I do it from VC? Maybe from
> the diff buffer?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 13:26 How to commit hunks using VC? Diogo F. S. Ramos
2018-10-26 14:34 ` Dan Čermák
@ 2018-10-26 15:56 ` Stefan Monnier
2018-10-26 16:43 ` Carlos Konstanski
` (2 more replies)
1 sibling, 3 replies; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 15:56 UTC (permalink / raw)
To: help-gnu-emacs
> Is it possible to commit only some hunks using VC?
Many years ago, I used a local patch to VC that allowed me to do
"partial commits". The way it worked, basically was:
- save/copy the current changes to some auxiliary file (there was no
`git stash` back then, but it was similar, except it didn't actually
change the files).
- then I could undo the hunks I didn't want to commit any which way
I wanted (using diff-mode or manual editing, you name it).
- upon commit the previously saved changes were automatically be
brought back.
Nowadays, you can basically do the same with `git stash`, but there's
indeed no "generic VC" support for it (only for the Git backend).
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 15:56 ` Stefan Monnier
@ 2018-10-26 16:43 ` Carlos Konstanski
2018-10-26 17:35 ` Eli Zaretskii
2018-10-26 18:03 ` Diogo F. S. Ramos
2 siblings, 0 replies; 17+ messages in thread
From: Carlos Konstanski @ 2018-10-26 16:43 UTC (permalink / raw)
To: Stefan Monnier, help-gnu-emacs
Though this does not technically answer the question, there is a very
nice plugin called magit. It's available from `list-packages'.
Carlos
Am Freitag, den 26.10.2018, 11:56 -0400 schrieb Stefan Monnier:
> > Is it possible to commit only some hunks using VC?
>
> Many years ago, I used a local patch to VC that allowed me to do
> "partial commits". The way it worked, basically was:
> - save/copy the current changes to some auxiliary file (there was no
> `git stash` back then, but it was similar, except it didn't
> actually
> change the files).
> - then I could undo the hunks I didn't want to commit any which way
> I wanted (using diff-mode or manual editing, you name it).
> - upon commit the previously saved changes were automatically be
> brought back.
>
> Nowadays, you can basically do the same with `git stash`, but there's
> indeed no "generic VC" support for it (only for the Git backend).
>
>
> Stefan
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 15:56 ` Stefan Monnier
2018-10-26 16:43 ` Carlos Konstanski
@ 2018-10-26 17:35 ` Eli Zaretskii
2018-10-26 18:44 ` Stefan Monnier
2018-10-26 18:03 ` Diogo F. S. Ramos
2 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-10-26 17:35 UTC (permalink / raw)
To: help-gnu-emacs
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 26 Oct 2018 11:56:02 -0400
>
> Nowadays, you can basically do the same with `git stash`
Why not "git commit --interactive"?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 15:56 ` Stefan Monnier
2018-10-26 16:43 ` Carlos Konstanski
2018-10-26 17:35 ` Eli Zaretskii
@ 2018-10-26 18:03 ` Diogo F. S. Ramos
2018-10-26 18:48 ` Stefan Monnier
2 siblings, 1 reply; 17+ messages in thread
From: Diogo F. S. Ramos @ 2018-10-26 18:03 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
>> Is it possible to commit only some hunks using VC?
>
> Many years ago, I used a local patch to VC that allowed me to do
> "partial commits". The way it worked, basically was:
> - save/copy the current changes to some auxiliary file (there was no
> `git stash` back then, but it was similar, except it didn't actually
> change the files).
> - then I could undo the hunks I didn't want to commit any which way
> I wanted (using diff-mode or manual editing, you name it).
> - upon commit the previously saved changes were automatically be
> brought back.
>
> Nowadays, you can basically do the same with `git stash`, but there's
> indeed no "generic VC" support for it (only for the Git backend).
Thank you. So, if I understand it correctly, I can commit hunks in VC,
with the git backend, by abusing stash, right?
Can I commit only parts of a hunk? Sometimes I edit hunks while using
`git add -p' because "split" doesn't cut them enough.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 17:35 ` Eli Zaretskii
@ 2018-10-26 18:44 ` Stefan Monnier
2018-10-26 19:34 ` Yuri Khan
0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 18:44 UTC (permalink / raw)
To: help-gnu-emacs
>> Nowadays, you can basically do the same with `git stash`
> Why not "git commit --interactive"?
Two reasons:
- The OP asks to do it with VC and VC supports `git stash` but not
`git commit --interactive`.
- I often find that I need to install only part of a hunk, which is
easy to do if you go through "stash + edit + commit + unstash".
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 18:03 ` Diogo F. S. Ramos
@ 2018-10-26 18:48 ` Stefan Monnier
0 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 18:48 UTC (permalink / raw)
To: help-gnu-emacs
> Thank you. So, if I understand it correctly, I can commit hunks in VC,
> with the git backend, by abusing stash, right?
Of course. And I don't think it's an abuse.
You can also do:
cp file file.bak
...edit file...
commit the file with VC
cp file.bak file
which is basically doing the same but using `cp` instead of `git stash`.
> Can I commit only parts of a hunk?
The commit is not linked to the stash, so you can commit anything
you like by adding/'removing the corresponding changes any way you
like, yes [ tho if you make those changes outside of Emacs, you'll
lose karma points, obviously. ]
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 18:44 ` Stefan Monnier
@ 2018-10-26 19:34 ` Yuri Khan
2018-10-26 19:42 ` Stefan Monnier
0 siblings, 1 reply; 17+ messages in thread
From: Yuri Khan @ 2018-10-26 19:34 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
On Sat, Oct 27, 2018 at 1:45 AM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> - I often find that I need to install only part of a hunk, which is
> easy to do if you go through "stash + edit + commit + unstash".
You have a pretty complex definition of easy.
In Magit, the status buffer displays a diff of my workspace against
the current branch, and I can stage lines in the marked region, or the
hunk at point, or the file at point, or all modified files, by
pressing ‘s’. Then, I commit by pressing ‘c c’.
If I need to commit a change that is finer than a single line, I can
press ‘RET’ on the relevant line in the diff, which takes me to the
buffer of the file at point, with point on the corresponding line. I
can edit the line, save the file, switch to the status buffer, stage
the line, switch back to the file, and undo the changes so that I
could put them in the next commit. Stash never enters the picture.
(If the goal is to use VC specifically, then I don’t know the answer.)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 19:34 ` Yuri Khan
@ 2018-10-26 19:42 ` Stefan Monnier
2018-10-26 19:57 ` Yuri Khan
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 19:42 UTC (permalink / raw)
To: help-gnu-emacs
> If I need to commit a change that is finer than a single line, I can
> press ‘RET’ on the relevant line in the diff, which takes me to the
> buffer of the file at point, with point on the corresponding line. I
> can edit the line, save the file, switch to the status buffer, stage
> the line, switch back to the file, and undo the changes so that I
> could put them in the next commit.
> Stash never enters the picture.
Whether you use "do ... undo" as above, or "cp foo foo.bak ... cp
foo.bak foo" or "stash ... unstash" is up to you. To me these are just
minor variants of the same approach.
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 19:42 ` Stefan Monnier
@ 2018-10-26 19:57 ` Yuri Khan
2018-10-26 19:59 ` Óscar Fuentes
2018-10-26 22:16 ` Michael Heerdegen
2 siblings, 0 replies; 17+ messages in thread
From: Yuri Khan @ 2018-10-26 19:57 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
On Sat, Oct 27, 2018 at 2:47 AM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > If I need to commit a change that is finer than a single line, I can
> > press ‘RET’ on the relevant line in the diff, which takes me to the
> > buffer of the file at point, with point on the corresponding line. I
> > can edit the line, save the file, switch to the status buffer, stage
> > the line, switch back to the file, and undo the changes so that I
> > could put them in the next commit.
> > Stash never enters the picture.
>
> Whether you use "do ... undo" as above, or "cp foo foo.bak ... cp
> foo.bak foo" or "stash ... unstash" is up to you. To me these are just
> minor variants of the same approach.
Essentially, yes, but do/undo operates on line level, cp on file
level, and stash/unstash on the whole working copy.
Also, the situation where you have one version of the line on the
branch, a different one in the working copy, and need to stage a third
one that differs from both of the above, is rare.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 19:42 ` Stefan Monnier
2018-10-26 19:57 ` Yuri Khan
@ 2018-10-26 19:59 ` Óscar Fuentes
2018-10-26 21:17 ` Stefan Monnier
2018-10-26 22:16 ` Michael Heerdegen
2 siblings, 1 reply; 17+ messages in thread
From: Óscar Fuentes @ 2018-10-26 19:59 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> If I need to commit a change that is finer than a single line, I can
>> press ‘RET’ on the relevant line in the diff, which takes me to the
>> buffer of the file at point, with point on the corresponding line. I
>> can edit the line, save the file, switch to the status buffer, stage
>> the line, switch back to the file, and undo the changes so that I
>> could put them in the next commit.
>> Stash never enters the picture.
>
> Whether you use "do ... undo" as above, or "cp foo foo.bak ... cp
> foo.bak foo" or "stash ... unstash" is up to you. To me these are just
> minor variants of the same approach.
Please note that the "do ... undo" method is only required with Magit to
commit "a change that is is finer than a single line".
I have a genuine interest on why some people avoid Magit. I stopped
recommending it on emacs.devel whenever a git question pops up because,
apparently, the people who post those questions are utterly uninterested
on a tool that solves their usability problems altogether :-)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 19:59 ` Óscar Fuentes
@ 2018-10-26 21:17 ` Stefan Monnier
2018-10-26 21:55 ` Óscar Fuentes
0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 21:17 UTC (permalink / raw)
To: help-gnu-emacs
Óscar Fuentes <ofv@wanadoo.es> writes:
[...]
> Please note that the "do ... undo" method is only required with Magit to
> commit "a change that is is finer than a single line".
Yuri Khan <yurivkhan@gmail.com> writes:
[...]
> Essentially, yes, but do/undo operates on line level, cp on file
> level, and stash/unstash on the whole working copy.
>
> Also, the situation where you have one version of the line on the
> branch, a different one in the working copy, and need to stage a third
> one that differs from both of the above, is rare.
Just to clarify: I did not intend to discourage people from using Magit
or any other option they like. I just described a hack I wrote before
Git even existed (and that I threw away since), and how to do something
similar within the confines of the actually available VC, as requested
by the OP.
> I have a genuine interest on why some people avoid Magit.
I don't avoid it: I just got used to using the command line for most Git
operations (probably dating back to using the command like for Bzr for
lack of an equivalent to the PCL-CVS that I maintained before).
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 21:17 ` Stefan Monnier
@ 2018-10-26 21:55 ` Óscar Fuentes
0 siblings, 0 replies; 17+ messages in thread
From: Óscar Fuentes @ 2018-10-26 21:55 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I have a genuine interest on why some people avoid Magit.
>
> I don't avoid it: I just got used to using the command line for most Git
> operations (probably dating back to using the command like for Bzr for
> lack of an equivalent to the PCL-CVS that I maintained before).
I was a happy PCL-CVS user, then psvn, then DVC and finally Magit as I
transitioned from a VCS to another. DVC (bzr) was the weaker one, barely
usable. I see Magit as rooted on the PCL-CVS philosophy but expanded to
the specific capabilities of Git. You not being a Magit user was quite
puzzling, but now it is explained :-)
I'll like to know the reasons of some of those that still nowadays ask
for help about git on emacs.devel, but I don't dare to ask them directly
:-)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 19:42 ` Stefan Monnier
2018-10-26 19:57 ` Yuri Khan
2018-10-26 19:59 ` Óscar Fuentes
@ 2018-10-26 22:16 ` Michael Heerdegen
2018-10-26 23:07 ` Stefan Monnier
2 siblings, 1 reply; 17+ messages in thread
From: Michael Heerdegen @ 2018-10-26 22:16 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Whether you use "do ... undo" as above, or "cp foo foo.bak ... cp
> foo.bak foo" or "stash ... unstash" is up to you. To me these are
> just minor variants of the same approach.
That all sounds uncomfortable. Doesn't VC provide something like "give
me the index version of the current file as a separate buffer" together
with a command to update the index from that buffer? Then you could do
anything you like with means of Emacs (like using Ediff to stage hunks),
and hit a key to update the index from the buffer (like C-c C-c) when
done.
Michael.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 22:16 ` Michael Heerdegen
@ 2018-10-26 23:07 ` Stefan Monnier
2018-10-27 0:22 ` Michael Heerdegen
0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2018-10-26 23:07 UTC (permalink / raw)
To: help-gnu-emacs
>> Whether you use "do ... undo" as above, or "cp foo foo.bak ... cp
>> foo.bak foo" or "stash ... unstash" is up to you. To me these are
>> just minor variants of the same approach.
>
> That all sounds uncomfortable. Doesn't VC provide something like "give
> me the index version of the current file as a separate buffer" together
> with a command to update the index from that buffer? Then you could do
> anything you like with means of Emacs (like using Ediff to stage hunks),
> and hit a key to update the index from the buffer (like C-c C-c) when
> done.
AFAIK VC doesn't provide that, but I guess it could/should.
Patches welcome (note that VC currently makes every effort to hide the
Git index/staging, so to work well, the patch will probably require
several changes. May I suggest Magit instead?).
Stefan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: How to commit hunks using VC?
2018-10-26 23:07 ` Stefan Monnier
@ 2018-10-27 0:22 ` Michael Heerdegen
0 siblings, 0 replies; 17+ messages in thread
From: Michael Heerdegen @ 2018-10-27 0:22 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> May I suggest Magit instead?
Yes, Magit provides both commands for using an Index buffer this way.
Most of the time I use my homebrew Ediff interface for staging, but I
also use the Magit interface a lot. It's a nice tool and eases the work
with Git where Git is inconvenient.
Michael.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2018-10-27 0:22 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-26 13:26 How to commit hunks using VC? Diogo F. S. Ramos
2018-10-26 14:34 ` Dan Čermák
2018-10-26 15:56 ` Stefan Monnier
2018-10-26 16:43 ` Carlos Konstanski
2018-10-26 17:35 ` Eli Zaretskii
2018-10-26 18:44 ` Stefan Monnier
2018-10-26 19:34 ` Yuri Khan
2018-10-26 19:42 ` Stefan Monnier
2018-10-26 19:57 ` Yuri Khan
2018-10-26 19:59 ` Óscar Fuentes
2018-10-26 21:17 ` Stefan Monnier
2018-10-26 21:55 ` Óscar Fuentes
2018-10-26 22:16 ` Michael Heerdegen
2018-10-26 23:07 ` Stefan Monnier
2018-10-27 0:22 ` Michael Heerdegen
2018-10-26 18:03 ` Diogo F. S. Ramos
2018-10-26 18:48 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).