Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all git commands have a dry-run option?

Tags:

git

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

like image 913
vfclists Avatar asked Apr 04 '10 08:04

vfclists


People also ask

What is dry-run in Git?

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 .

What is dry-run option?

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.

What is the difference between git commit and dry run?

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).

Should I use Git merge--Dry Run or--dry-run?

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.

What is the--Dry-Run option in Git used for?

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.

What is the best way to run Git commands?

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.


2 Answers

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).

like image 126
VonC Avatar answered Sep 30 '22 00:09

VonC


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.

like image 21
Amber Avatar answered Sep 30 '22 00:09

Amber