Bozho
Bozho

Reputation: 597432

How not to push a given commit

I accidentally committed some huge files (300MB). Then I made other commits, and realized that the huge files should not go into the repository, so I deleted them.

However, when pushing, mercurial tries to send the changesets chronologically, which means it first tries to push the huge files. Which didn't succeed after 2 hours of waiting. So, can I get rid of that particular commit(changeset) without affecting the rest?

Or I should delete the whole project, pull a fresh copy and re-apply my other changes manually?

Upvotes: 0

Views: 81

Answers (3)

Laurens Holst
Laurens Holst

Reputation: 21086

I usually find that the rebase and strip commands are very useful tools for this kind of history modification operation; you can rebase all your changes made after the bad commit on top of its parent, and then strip the bad changeset.

Say <bad> is the bad changeset that you want to remove, <parent> is its parent and <child> is the child which you want to keep:

hg rebase -s <child> -d <parent>
hg strip <bad>

Example:

$ hg log -G
@  changeset:   2:6d0685591967
|  summary:     after
|
o  changeset:   1:fab6b3f4effa
|  summary:     bad
|
o  changeset:   0:0233d1f3547c
   summary:     before

$ hg rebase -s 2 -d 0
saved backup bundle to .hg/strip-backup/6d0685591967-backup.hg
$ hg log -G
@  changeset:   2:b0fa9ee8533f
|  parent:      0:0233d1f3547c
|  summary:     after
|
| o  changeset:   1:fab6b3f4effa
|/   summary:     bad
|
o  changeset:   0:0233d1f3547c
   summary:     before

$ hg strip 1
saved backup bundle to .hg/strip-backup/fab6b3f4effa-backup.hg
$ hg log -G
@  changeset:   1:b0fa9ee8533f
|  summary:     after
|
o  changeset:   0:0233d1f3547c
   summary:     before

As you can see, the bad changeset is now gone.

Note that for rebase and strip to work you need to enable the rebase and mq extensions. Also be sure to make a backup copy of your repository before performing this history modifying operation.

Upvotes: 2

Craig Stuntz
Craig Stuntz

Reputation: 126587

You don't have to re-apply your other changes entirely manually. You can export them and then import them to your fresh repository copy.

Upvotes: 1

Chris G
Chris G

Reputation: 7050

As long as the push didn't complete, you can try enabling the "mq" extension and you can delete a commit that hasn't been pushed.

Upvotes: 1

Related Questions