97

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

vfclists
  • 19,193
  • 21
  • 73
  • 92

2 Answers2

86

Not every command would naturally support a dry run directly.

  • git merge has its own option (git merge --no-commit --no-ff)
  • but git pull does not really need it ('git fetch origin', then a 'git log master..origin/master', before a git merge origin/master)
    (but git push has a dry-run option)

As J.C. Hamano summarizes:

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.


iboisver comments:

Another thing to be aware of is that commands like git add and git rm allow the -n command-line option to specify dry run, while in git commit, the -n option means something completely different.
So be sure to check the man page

git commit -n:

-n
--no-verify

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Another thing to be aware of is that commands like `git-add` and `git-rm` allow the _-n_ command-line option to specify dry run, while in `git-commit`, the _-n_ option means something completely different. So be sure to check the man page. – iboisver May 03 '12 at 06:38
  • 1
    @iboisver interesting feedback, thank you. I have included your comment in the answer for more visibility. – VonC May 03 '12 at 06:45
  • I would have wanted --dry-run on "git stash", especially when pushing a directory "git stash push -- /dir" – Gaurang Patel Feb 21 '19 at 21:08
  • @GaurangPatel Agreed. That was discussed in 2017 here: https://public-inbox.org/git/CA+CzEk8QiSu4heMDsx7XC729UEPNm6hdZfs9W5uwoJBvuLWr+w@mail.gmail.com/ – VonC Feb 21 '19 at 22:20
14

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

Community
  • 1
  • 1
Amber
  • 507,862
  • 82
  • 626
  • 550