"commit --amend" and extraneous files

Steve Fink sphink at gmail.com
Wed Feb 5 16:26:41 UTC 2020


On 2/4/20 5:25 AM, Victor Sudakov wrote:
> Malcolm Matalka wrote:
>>
>>> If I wanted to commit just several files:
>>>
>>> hg commit -m "Foo" file1.c file2.c
>>>
>>> and instead committed the whole working dir:
>>>
>>> hg commit -m "Foo"
>>>
>>> What is the right way to amend the problem (so that files other than
>>> file1.c and file2.c become uncommitted again)?
>> Check out `hg backout` and `hg histedit` (I think they require an
>> extension.
> I can also probably `hg strip` the tip revision, but are you sure the
> desired effect cannot be achieved with "commit --amend" as stated in the
> subject line?
>
> And I don't want to use `hg backout` because I don't want to keep the
> erroneous commit in the repo.

I think `hg commit --amend` always keeps the existing commit's changes, 
and just adds in new ones. So I guess you could do `hg revert -X file1.c 
-X file2.c` followed by `hg commit --amend`, but then you'd need to 
restore all your changes from the .orig files.

Perhaps something like `hg update -r tip^; hg diff -c tip | patch -p1` 
and then recreate your commit (and ignore or strip the old one)?

This is much easier with the evolve extension, which is how I would do 
it. I'd use `hg uncommit -a; hg amend file1.c file2.c` though I think it 
would work in a single command with just `hg uncommit -X file1.c -X 
file2.c`. (My brain has never managed to properly grasp the -I and -X 
options, so I always fall back to undoing everything and then redoing 
the individual pieces with `hg amend` or `hg amend -i`.)





More information about the Mercurial mailing list