Commit individual lines in Mercurial?
Asked Answered
O

3

5

I'm using Workbench, but if there's a command line solution for this or some extension, I'm open to that as well.

I'm constantly working in config files per environment (working in .NET, so please no answers a la "change your config files" etc) and at times I need to commit specific updates to the file. I've seen this behavior in Github for Mac client, but is anything like this available in Mercurial/Workbench? e.g.

web.config

config value="123"
whatever blah blah

change both lines e.g.

config value="42"
whatever

My goal is to commit only line 2 (whatever) while not committing line 1 (config value="42")

Omura answered 9/4, 2014 at 14:25 Comment(0)
M
4

You probably need RecordExtension which is shipped with Mercurial but has to be enabled to be used.

Moly answered 9/4, 2014 at 15:11 Comment(1)
Record can't see any change smaller than a diff hunk, so consecutive lines will be treated as one single change. While some diff implementations let you override the hunk size, Record doesn't have that sharp of a knife when splitting hairs.Rivers
D
3

The Record Extention isn't up to the job in this case. It will lump the two changes into a single hunk which you can include or not, but it won't allow you to split them.

What you need is the CRecord Extention, as that allows you to select individual lines. It's also a nicer interface.

Edit: Since writing this, Record and CRecord have been folded into core. commit -i is now equivalent to record, and if you add this to your .hgrc the record commands will use the nicer interface.

[ui]
interface=curses                                                      
Drastic answered 11/4, 2014 at 18:35 Comment(3)
According to mercurial-scm.org/wiki/CrecordExtension CRecord is included, but I can't figure out how to use it with TortoiseHg. Is it only available with command line interface?Credence
Yes, CRecord is a command line interface. I don't know much about TortoiseHG as I don't use it, but a quick look at the documentation seems to suggest it has a similar feature. Change SelectionDrastic
I am using Git Gui and thinking of switching to TortoiseHg. I often use the stage hunk and stage line commands. According to the page you mention and all the documentation I was able to find, TortoiseHg can only do the stage hunk, not the stage line, so I will keep Git. Thanks for your answer.Credence
B
0

hg record ou hg commit -i will do the job, but you have to use the e command in order to manually edit the patch. In your case, you will have to replace:

-config value="123"
-whatever blah blah
+config value="42"
+whatever

to

 config value="123"
-whatever blah blah
+whatever

It is not the best UI, but it does the job.

Bernita answered 25/7, 2019 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.