我添加这个答案不是因为它比公认的答案更好,而是因为它澄清了“hg status”之间的区别。和“汞状态 $(汞根)”。这可能会让一些评论者感到困惑 - 更糟糕的是,这可能会导致忘记检查必要的东西。
“汞状态。”仅使用相对路径报告 . 下面的子树的状态。
"hg status $(hg root)" 使用相对于 CWD 的路径报告整个 repo 的状态。
两者都有用。
(一般来说,“hg status path”显示路径下子树的状态(如果 path = $(hg root),则整个 repo”,但相对于 CWD。(我必须承认我觉得这很混乱,因为有发生了两件事:获取状态的子树和显示相对路径的 cwd。))
下面嵌入的 shell 会话示例显示了这一点。
$ bash [~/hack] 562 $> mcd hg-test
./hg-test
$ bash [~/hack/hg-test] 563 $> hg init .
$ bash [~/hack/hg-test] 564 $> mkdir subdir
$ bash [~/hack/hg-test] 565 $> touch foo
$ bash [~/hack/hg-test] 566 $> touch subdir/bar
$ bash [~/hack/hg-test] 567 $> hg status
? foo
? subdir/bar
$ bash [~/hack/hg-test] 552 $> hg status $(hg root)
? foo
? subdir/bar
$ bash [~/hack/hg-test] 552 $> cd subdir
./subdir
$ bash [~/hack/hg-test/subdir] 553 $> hg status
? foo
? subdir/bar
$ bash [~/hack/hg-test/subdir] 553 $> hg status .
? bar
$ bash [~/hack/hg-test/subdir] 513 $> hg status $(hg root)
? ../foo
? bar
$ bash [~/hack/hg-test/subdir] 523 $> hg status
? foo
? subdir/bar
因此,如果你想做一些事情,比如在本地子树中备份文件,而不签入,然后恢复(我在使用“hg lock”时经常需要这样做,因为我使用的 FrameMaker 文件不能在 hg 中进行差异或合并(或几乎没有):
$ bash [~/hack/hg-test/subdir] 523 $> mkdir bak; hg status -n . | xargs cp --target-directory bak
$ bash [~/hack/hg-test/subdir] 524 $> ls bak
bar
但是如果要备份树中所有按状态报告的文件
$ bash [~/hack/hg-test/subdir] 528 $> mkdir bak-root; hg status -n $(hg root) | xargs cp --target-directory bak-root
cp: will not overwrite just-created `bak-root/bar' with `bar'
$ bash [~/hack/hg-test/subdir] 529 $> ls bak-root
bar foo
顺便说一下,警告显示了文件名冲突的问题。我通常使用一个小工具,我必须添加一个 .bak 后缀或 xargs。但是这个例子就足够了。
顺便说一句^2,我通常用“hg status -nm”来做这样的事情,但上面的例子就足够了。