我正在为不同的项目使用mercurial和git,并且喜欢它们.我觉得有点恼火的是,"hg status"显示了相对于存储库根目录的路径,而不是当前目录(与git不同).可以通过某种方式调整此行为吗?
Gio*_*das 35
要查看相对于当前目录的工作空间状态,您始终可以使用"." (单点)作为"hg status"的参数,即:
% hg root # root of the workspace
/work/foo
% pwd # current directory is <root>/src
/work/foo/src
% hg status # no argument, see all files
M etc/foo.conf # all files are shown with paths
M src/foosetup.c # relative to workspace root
%
Run Code Online (Sandbox Code Playgroud)
明确要求当前工作目录时的区别在于相对文件名路径使用它作为起点:
% hg status . # see only files under current path
M foosetup.c
%
Run Code Online (Sandbox Code Playgroud)
ric*_*chq 33
通常的解决方法是运行:
hg status $(hg root)
Run Code Online (Sandbox Code Playgroud)
对于旧版本的Mercurial,在1.7之前,您可以使用此hack,添加到存储库的".hg/hgrc"文件中:
[alias]
sst = status /path/to/root
Run Code Online (Sandbox Code Playgroud)
这需要启用别名扩展,因此您可能必须在〜/ .hgrc文件中添加"alias =".
从Mercurial 1.7开始,别名扩展了解了"!" 转义为使用shell命令,因此您现在可以拥有一个执行此操作的全局别名:
[alias]
sst = !hg status $($HG root) $HG_ARGS
Run Code Online (Sandbox Code Playgroud)
不要使用st = !hg status $(hg root),因为它会创建一个无限循环,一遍又一遍地运行hg状态.它看起来像是别名解析中的一个错误 - 如果你想使用别名hg status来显示来自根的路径,那么下面的咒语在全局$ HOME/.hgrc中起作用:
[alias]
__mystatus = status
st = !hg __mystatus $($HG root) $HG_ARGS
Run Code Online (Sandbox Code Playgroud)
从旧的mercurial版本(从2008年开始> = 1.1)开始工作的标准方法是:
hg status re:
Run Code Online (Sandbox Code Playgroud)
产量:
M ../contrib/buildrpm
M ../hg
M httprepo.py
Run Code Online (Sandbox Code Playgroud)
自mercurial 1.3(2009)以来,您可以根据alias需要定义:
[alias]
sst = status re:
Run Code Online (Sandbox Code Playgroud)
这种行为最终记录在3.4(2015)中:
$ hg help status --verbose
[...]
- show changes in the working directory relative to the current directory
(see 'hg help patterns' for more information):
hg status re:
Run Code Online (Sandbox Code Playgroud)
自mercurial 4.2(2017年5月)以来,您可以告诉status命令始终打印相关路径,将其放入您的hgrc:
[commands]
status.relative = True
Run Code Online (Sandbox Code Playgroud)
直接在命令行上测试(hg> = 4.2):
$ hg --config commands.status.relative=True status
M ../contrib/buildrpm
M ../hg
M httprepo.py
Run Code Online (Sandbox Code Playgroud)
最后,介绍了mercurial 4.3ui.tweakdefaults,除其他外,它将一些默认值更改为更现代的默认值:
[ui]
# hg status prints relative paths
# hg diff produces patches in git format
tweakdefaults = True
Run Code Online (Sandbox Code Playgroud)
如果你使用现代的mercurial(> = 4.3),这是官方推荐的方式.
| 归档时间: |
|
| 查看次数: |
7616 次 |
| 最近记录: |