Matthew Schinckel
Matthew Schinckel

Reputation: 35649

How do I only commit a subrepo's changes?

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.

Upvotes: 9

Views: 3826

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78350

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.

Upvotes: 11

Related Questions