Perform an empty commit with mercurial

ⅰ亾dé卋堺 提交于 2019-11-30 17:33:07

You can use hg commit --amend to create empty commits.

Just create an arbitrary commit and backout the change. Afterwards fold both commits together.

Example:

touch tmp                               # create dummy file
hg add tmp                              # add file and...
hg commit -m "tmp"                      # ... commit
hg rm tmp                               # remove the file again and ...
hg commit --amend -m "empty commit"     # ... commit

You can make commit that's closing the branch:

hg commit --close-branch -m "message"

Update:

You can close branch once, but it can be reopened with another commit. Simplest way to reopen branch without changing files is to tag some revision. So you can use hg commit --close-branch for empty commit and then hg tag for reopening.

Update v2

Actually you can create new empty commits with just hg tag command. It has -m parameter for setting a commit message. If you don't really care about correctness of this tags, you can use just one tag name by calling hg tag with -f parameter:

hg tag t1 -f -m "message"

You can now create empty commits by just doing hg ci -m "empty commit"

e.g.

hg branch my-next-branch
hg ci -m "empty commit"

Will create a my-next-branch with a single empty commit that you can push to the remote repo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!