How do I get mercurial to show the diff during `hg com`?

守給你的承諾、 提交于 2019-12-10 04:17:20

问题


Is there a way to configure hg com so that in the commit message file that pops up in the external editor, instead of just showing which files were changed (in the HG: lines) it actually shows the full diff? I'd rather view the output and compose my commit message simultaneously from the comfort of my text editor as opposed to doing hg diff on the command line separately beforehand.


回答1:


TortoiseHg does this out of the box: a top panel for the commit message and below that, a left pane listing the affected files and a right pane showing the diffs, one after the other.




回答2:


As of 2016, it's possible to do this with the committemplate configuration option. Adding the following to an hgrc file will include the diff in the editor window inline as you type your commit message.

[committemplate]
changeset = {desc}\n\n
    HG: {extramsg}
    HG: user: {author}\n{ifeq(p2rev, "-1", "",
   "HG: branch merge\n")
   }HG: branch '{branch}'\n{if(currentbookmark,
   "HG: bookmark '{currentbookmark}'\n")  }{subrepos %
   "HG: subrepo {subrepo}\n"              }
   {splitlines(diff()) % 'HG: {line}\n'}

See hg help hgrc and search for committemplate for more information.




回答3:


Mercurial doesn't have that as a built-in feature, but it's easy to simulate in your editor (as launched by commit).

Here's an example using VIM: https://www.mercurial-scm.org/wiki/DiffsInCommitMessageInVIM

The hgeditor script https://www.mercurial-scm.org/hg/hg-stable/raw-file/tip/hgeditor provides further examples.

The basic jist is:

  1. at editor launch run hg diff redirecting to a temp file
  2. have your editor load both the commit message file and the diff


来源:https://stackoverflow.com/questions/2683226/how-do-i-get-mercurial-to-show-the-diff-during-hg-com

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