9

I have a master repo, which has some changes I do not want to commit.

I have a subrepo, which has changes that have already been committed.

I want to commit the changes subrepo revision in my master repo, without committing the changes to the files in the master repo.

I cannot seem to do this. I can't commit .hgsubstate, and making a trivial change to a file to commit that does not commit the subrepo changes to the master repo.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
  • If your modified files are named `foo` and `bar`, have you tried doing `hg ci -S -X foo -X bar`? – Helgi Jun 19 '12 at 09:17

1 Answers1

11

Pass the name of the subrepo itself to commit and Mercurial will update .hgsubstate and commit it.

ry4an@four:~$ hg init main
ry4an@four:~$ cd main
ry4an@four:~/main$ hg init sub
ry4an@four:~/main$ echo sub = sub > .hgsub
ry4an@four:~/main$ hg add .hgsub
ry4an@four:~/main$ hg commit
ry4an@four:~/main$ cd sub
ry4an@four:~/main/sub$ echo text > afile
ry4an@four:~/main/sub$ hg commit -Am first-in-sub
adding afile
ry4an@four:~/main/sub$ cd ..
ry4an@four:~/main$ hg status
ry4an@four:~/main$ echo text > dont-commit-me
ry4an@four:~/main$ hg add dont-commit-me
ry4an@four:~/main$ hg status
A dont-commit-me
ry4an@four:~/main$ cat .hgsubstate
0000000000000000000000000000000000000000 sub
ry4an@four:~/main$ hg commit -m 'subrepo only' sub
ry4an@four:~/main$ hg status
A dont-commit-me
ry4an@four:~/main$ cat .hgsubstate
dec5eaa9e22cd0a05cbba3ba02fdb0e1f243e07e sub

Note that the file in main dont-commit-me never got committed, but the .hgsubstate was updated.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • That did the trick. I can't believe I didn't think to try that! – Matthew Schinckel Jun 20 '12 at 04:57
  • This is a little misleading, since `dont-commit-me` wouldn't have been committed anyway. If it had been added, then the argument to `commit` would make a difference. (I defer to Ry4an, though, as I know he is a Mercurial master.) – harpo Nov 26 '13 at 15:26
  • You're right, @harpo . I should've added it for it to be a better example. – Ry4an Brase Nov 26 '13 at 19:19
  • In Hg (without a dummy file), I am getting "nothing changed". When I add a dummy file I get an error "uncommitted changes in subrepository". Seems like failed use-case handling.. – user2864740 Dec 21 '15 at 23:51