What is the meaning of the "bang" or "!" before the git command?
Asked Answered
W

2

16

As you can see from this excerpt, there is a "!" before the git command. What's the point?

[alias]
commitx = !git add . && git commit

- https://mcmap.net/q/332243/-git-commit-auto-add-new-folders-or-files

I understand aliases and what the command itself is doing, but not the point of the "!" before the git command.

Wilburnwilburt answered 17/5, 2012 at 18:30 Comment(0)
K
25

The ! means "run the following as commands to the shell", so in this case the alias git commitx expands to the equivalent of running git add . && git commit (which is a terrible terrible idea)

Kuehl answered 17/5, 2012 at 18:37 Comment(1)
Thanks for the quick and concise answer! Also agree it is a bad idea. Thanks again!Wilburnwilburt
K
18

An important aspect of ! not covered by the accepted answer is that for the shell command, the working directory is set to the top level of the working copy. Therefore, git commitx would stage then commit all new and changed files in the working copy, while running git add . && git commit manually would stage then commit all new and changed files in the current directory.

Kinase answered 3/8, 2012 at 20:15 Comment(2)
Is there anyway to achive the same shell execution, but without changing working dir to top level?Overspread
@Overspread Not that I know ofKinase

© 2022 - 2024 — McMap. All rights reserved.