Do all git commands have a --dry-run option, or one which would indicate what the command would do without actually doing them?
It allows you to create a commit with an empty commit message without using plumbing commands like git-commit-tree[1]. This option determines how the supplied commit message should be cleaned up before committing. The <mode> can be strip , whitespace , verbatim , scissors or default .
A dry run (or a practice run) is a testing process where the effects of a possible failure are intentionally mitigated. For example, an aerospace company may conduct a "dry run" test of a jet's new pilot ejection seat while the jet is parked on the ground, rather than while it is in flight.
Another thing to be aware of is that commands like and -n command-line option to specify dry run, while in git commit, the option means something completely different. This option bypasses the pre-commit and commit-msg hooks. See also githooks (5).
In that case you should use. git merge --dry-run. Many commands have a dry run option. To be safe, just check the help docs for the command you want to dry run to make sure you're dry-run ambitions don't end in frustration and redundant tears.
The --dry-run option can be used to obtain a summary of what is included by any of the above for the next commit by giving the same set of parameters (options and paths). If you make a commit and then find a mistake immediately after that, you can recover from it with git reset.
You may have already guessed it, but the simplest way to run git commands is exactly as you have done, right in the terminal. You can also use PowerShell if you wish, which is useful if later you wish to create complex procedures with git commands. My personal preference however is to use the git bash shortcut in Windows.
Not every command would naturally support a dry run directly.
git merge --no-commit --no-ff
)git fetch origin
', then a 'git log master..origin/master
', before a git merge origin/master
)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
andgit rm
allow the-n
command-line option to specify dry run, while ingit 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).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With