"hg commit" - nothing happens! - mercurial

I just started my first Mercurial project.
I did a 'cd' into my source directory.
Then I did this:
hg init myproject
But next I did
hg commit -m "first commit"
And all it reports is:
nothing changed
But when I do
hg status
It lists all of the source code in my project.
What am I doing wrong here?

I think the output of the hg status command is probably telling you that you have a lot of files in your working directory that are not being tracked by Mercurial. You should be able to fix this by running the command
hg addremove
Then you can make your first commit:
hg commit -m "first commit"
Alternatively, you can do this all in one command with
hg commit -A -m "first commit"

Try hg push then refresh the repository some times It changes inspite of saying nothing changed

Related

How to make a Mercurial commit with no files?

I'm looking for the Mercurial equivalent of git commit --allow-empty for testing purposes.
Can't be done. There doesn't have to be a change to a source file, but you have to have changes something, be it file permissions, branch name, tag, or something.
You say "for testing purposes". If that's the case I usually just use
echo another line >> README ; hg commit -m 'added another line'
I can hit up-arrow enter on that plenty fast.
I think the best solution I've found is:
touch foo
hg add foo
hg commit -m 'Empty commit'
hg rm foo
hg commit --amend
Works with MQ. Make a MQ changeset with some dummy change, then revert the change and refresh (hg qref) the patch. Voila.

hg merge says outstanding uncommitted changes; hg commit says nothing changed -- how to exit the loop?

The problem here is that hg' workflow apparently leads in a circle:
hg pull, get another head
hg merge, get warned of outstanding
uncommitted changes
hg commit -m "pre merge commit", get message
saying nothing changed
go to 2 hg status, see output like the
following:
! #foo.py#
? junk.out
? junk2.out
If foo.py is in your list of .hg-ignore'd files try specifying it explicity on the command line when you commit.
e.g.
hg commit -m "commit message" ./#foo.py
edit: looking more closely at your error: the file has been deleted (! in the status list), but hg hasn't tracked the deletion. You need to tell hg about the deletion using:
hg rm -A ./foo.py
The -A / --after means record the removal after it actually occured

Mercurial: roll back an "hg commit --amend".

I accidentally did a "hg commit --amend" instead of just a commit. How can I roll back the commit to before the amend?
You can use hg reflog (from the journal extension) and hg reset <hash>.
hg reflog -v
should give something like:
<old-hash> -> <new-hash> <user> <timestamp> commit --amend <some-path>
if that is the amend you want to revert, just use:
hg reset <old-hash>
The commit will be reverted to what is previously was and the changes that were amended should now be uncommitted changes (check using hg status and hg diff).
If your version of Mercurial is new enough, I believe you should be able to use the hg unamend command from the uncommit extension that ships with Mercurial. This may require that obsolescence markers are enabled, I'm not sure.
Enable the uncommit extension, add this to your ~/.hgrc:
[extensions]
uncommit =
Actually run the unamend:
hg unamend
Find the latest saved backup in .hg/strip-backup directory
hg unbundle .hg/strip-backup/<latest backup>
Now you should have two heads - one with the amended commit, other one with two commits (first one - old commit before amending, second one caled: "temporary amend commit for (old commit hash)".
if you have histedit extension, you can do hg histedit on it in order to change it (e.g. select edit in order to achieve a state just before the commit, i.e. when you can see all changes using hg diff).
Don't forget to strip the old head.
It's 2022, and my attempts to use hg unamend have not worked. histedit is too clunky for my purposes, but the solution proposed by mariu52 elsewhere on this page can easily be adapted to work without histedit. It relies on the -k option of the strip subcommand.
In a nutshell:
Find the latest saved backup in the .hg/strip-backup/ directory
Run hg unbundle .hg/strip-backup/<latest backup> where <latest backup> signifies the full filename.
Run hg heads and note the rev number corresponding to the amendment.
Let's call this $AMENDREV; this is the rev number we will strip in the next step.
Run hg strip -k --rev $AMENDREV
Using the -k option in the strip command is critical.
WARNING: this procedure will in effect erase the memory of any add or remove commands
that were pending when the amend command was executed.
For example, in the transcript below, the hg add file2 command is effectively
forgotten after the strip command is executed.
For clarity, here's a transcript based on the above recipe.
$ mkdir tmp ; cd tmp
$ ls
$ echo 1 > file1
$ echo 2 > file2
$ hg init
$ ls
file1 file2
$ hg add file1
$ hg commit -m 'one file'
$ hg add file2
$ hg amend -m 'amendment'
saved backup bundle to /tmp/tmp/.hg/strip-backup/d332ee829c21-5a5f23b0-amend.hg
$ hg unbundle -u .hg/strip-backup/d332ee829c21-5a5f23b0-amend.hg
adding changesets
adding manifests
adding file changes
added 1 changesets with 0 changes to 1 files (+1 heads)
new changesets d332ee829c21 (1 drafts)
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
updated to "1a445f3252eb: amendment"
1 other heads for branch "default"
$ hg heads
1[tip]:-1 d332ee829c21 2022-11-09 01:55 -0500 peak
one file
0 1a445f3252eb 2022-11-09 01:55 -0500 peak
amendment
$ ls
file1 file2
$ hg strip -k -r 0
saved backup bundle to /tmp/tmp/.hg/strip-backup/1a445f3252eb-bfaab5ec-backup.hg
$ ls
file1 file2
$ hg list
r0: peak tip 2022-11-09 01:55 -0500
one file
file1
$
hg unamend part of Mercurial 4.5 (2018-02-01).
NOTE: This answer is now deprecated. See the answer from #Sorina Sandu instead.
See hg help commit, where it says:
The --amend flag can be used to amend the parent of the working
directory with a new commit that contains the changes in the parent in
addition to those currently reported by "hg status", if there are any.
The old commit is stored in a backup bundle in ".hg/strip-backup" (see
"hg help bundle" and "hg help unbundle" on how to restore it).

mercurial: including precommit-changed file

On commit to repository I have a hook defined in Mercurial:
[hooks]
precommit.exportDB=exportDB.bat
This creates/updates a SQL-dump from my database, which should be included in the commit.
BUT: although this works, the Sql is marked as new, but not part of the now commiting changeset.
How can I automatically include it so it gets into the set of changed files?
Hope this makes sense...
Thx
Reinhard
This'll sound crazy, but you can do it in two steps. First change your precommit hook to a pre-commit hook -- yup, both exist and they're different. Without the dash the commit has already started and some lock has been acquired. With the dash it happens before the commit starts and you can still hg add the new file.
On a unix like that total change would be:
[hooks]
pre-commit.exportDB=exportDB.sh && hg add resulting.sql
presumably there's something similar on Windows, or you could make the hg add the last line of the batch file.
P.S. Don't commit generated files. :)
Update:
I just tested this and it works as I suggested:
ry4an#four:~$ hg init reinhard
ry4an#four:~$ cd reinhard/
ry4an#four:~/reinhard$ vi .hg/hgrc
ry4an#four:~/reinhard$ cat .hg/hgrc
[hooks]
pre-commit = hg add otherfile
ry4an#four:~/reinhard$ echo text > afile
ry4an#four:~/reinhard$ echo more > otherfile
ry4an#four:~/reinhard$ hg add afile
ry4an#four:~/reinhard$ hg status
A afile
? otherfile
ry4an#four:~/reinhard$ hg commit -m 'message'
ry4an#four:~/reinhard$ hg status --all
C afile
C otherfile
Notice that before the commit only 'afile' is added and 'otherfile' is unknown, and after the commit both files are 'C' (meaning "Clean' -- they've been added and committed).

Generating patches in Mercurial

I've looked for that in the manual, but I can't generate a patch for the last commit.
I tried
hg qnew patch_name
but it does only file with
# HG changeset patch
# Parent a6a8e225d16ff5970a8926ee8d24272a1c099f9c
I also tried
hg export tip
but it doesn't do anything. I committed the changes exactly.
How to generate a patch file with the last commit in?
The command to do this is export:
$ hg export -o FILE -r REV
It doesn't require redirection and will thus work correctly on any platform/shell.
Your hg export tip is the best way to do it, and the hg diff and hg log based answers are just lesser versions of the same. What exactly do you see/get when you type hg export tip? What does the output of hg log -p -r tip show?
The changeset tip is just means "the changeset that most recently arrived in my repository" which isn't as useful a concept as you might think, since hg pull and hg tag all create changesets too. If you really want the last thing you committed you'll need a more precise revspec.
Like so:
hg diff -r tip > tip.patch
You can use this command:
hg log -r tip -p > tip.patch
this will generate a patch for just that revision.
If you want to convert the latest commit to a patch file, use
hg qimport -r tip
This will replace the topmost regular commit with an applied MQ patch file.
To generate patches using "mq extensions" in mercurial, you can follow the below given steps. This will create a patch using mercurial:
1) Enabling mq extensions: Add the following lines to your hgrc file and save it.
[extensions]
mq =
2) Creating a patch using mq extensions: To create a patch using mq extensions you can do the following.
hg qnew -e -m "comment you want to enter" bug_name.patch
In the above command, -e flag is for editing the patch and -m flag is for adding a message to the patch.
3) Updating the patch: For updating the patch, you can use the following command when a patch is already applied.
hg qrefresh