所有 git 命令都有试运行选项吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2573905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:11:29  来源:igfitidea点击:

Do all git commands have a dry-run option?

git

提问by vfclists

Do all git commands have a --dry-run option, or one which would indicate what the command would do without actually doing them?

是否所有 git 命令都有一个 --dry-run 选项,或者一个可以指示命令在不实际执行的情况下会做什么的选项?

采纳答案by VonC

Not every command would naturally support a dry run directly.

并非每个命令都会自然地直接支持试运行。

  • git merge 有它自己的选项( git merge --no-commit --no-ff)
  • git pull 并不真正需要它(' git fetch origin',然后是 ' git log master..origin/master',在 a 之前git merge origin/master
    (但git push有一个空运行选项)

As J.C. Hamano summarizes:

正如JC Hamano 总结的那样

There are things that are not implemented in git because they do not make sense, and there are things that are not implemented in git because nobody had itch to scratch for.
To put it differently, we tend to implement only things that there are actual, demonstrated needs for from real world and only when the addition makes sense as a coherent part of the system.

有些东西没有在 git 中实现,因为它们没有意义,有些东西没有在 git 中实现,因为没有人想要抓挠。
换句话说,我们倾向于只实现现实世界中存在实际的、已证明的需求,并且只有当添加作为系统的一个连贯部分有意义时。



iboisvercomments:

iboisver评论:

Another thing to be aware of is that commands like git addand git rmallow the -ncommand-line option to specify dry run, while in git commit, the -noption means something completely different.
So be sure to check the man page

另一件要注意的事情是,像git addgit rm允许-n命令行选项指定试运行命令,而在 中git commit,该-n选项意味着完全不同的东西。
所以一定要检查手册页

git commit -n:

git commit -n

-n
--no-verify

This option bypasses the pre-commit and commit-msg hooks. See also githooks(5).

此选项绕过 pre-commit 和 commit-msg 挂钩。另请参阅githooks(5)

回答by Amber

While there isn't always a --dry-runflag for every comment, there are usually equivalents. For example, this previous questionshows what to do for git merge.

虽然并非--dry-run每条评论总是有一个标志,但通常有等价物。例如,上一个问题显示了要为git merge.