Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg equivalent of git add -p?

Is there a mercurial equivalent of git add -p?

Quoting from man, git-add with the option -p (or --patch) does the following:

Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

like image 831
andreliebschner Avatar asked Oct 14 '11 08:10

andreliebschner


People also ask

What is Hg in Git?

The Hg-Git plugin can convert commits/changesets losslessly from one system to another, so you can push via a Mercurial repository and another Mercurial client can pull it. In theory, the changeset IDs should not change, although this may not hold true for complex histories. Commands.

Can GitHub use Mercurial?

Overview. This extension adds the ability to work on a Git repository from Mercurial. It also allows using a Git server as a collaboration point for a team with developers using both Git and Mercurial.

Is Git add mandatory?

The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything. Sometimes, git add can have a reputation for being an unnecessary step in development.

Does GitLab work with Mercurial?

There is no current plan to add Mercurial support to GitLab, but we are providing support to the Octobus team where needed as they work on Heptapod.


2 Answers

Have a look at the record extension (which comes bundled with Mercurial).

Note that since Mercurial doesn't have the concept of the staging area like git, running hg record will simply allow you to examine, hunk by hunk, the modifications in your working copy. Any changes you choose to record will be committed, and any changes you choose not to record are simply left as modifications in your working copy.

like image 135
bjlaub Avatar answered Oct 11 '22 19:10

bjlaub


The Record Extension is the standard tool for this. It allows you to pick hunks to include or not in a commit. Once you've enabled the extension in your hgrc, the command is just

hg record 

The CRecord Extension gives you a TUI (Text User Interface) on top of this which allows you to go down to which lines you want to include. This isn't standard though, so it need downloading to a directory before you can enable it in your hgrc.

hg crecord 

Edit:

  1. The Record extension is no longer necessary since approx v3.4. Now various commands support the -i or --interactive flag. For example:

    hg commit -i 

    ...will ask you hunk by hunk what you want to include.

  2. CRecord made it in to 3.8 as a core feature. Add the following to your .hgrc

    [ui] interface = curses 

    Now, --interactive commands will bring up the same interface as the old CRecord extension.

like image 33
Paul S Avatar answered Oct 11 '22 19:10

Paul S