# 'git add' option to non-interactively stage working tree changes

5 messages from 2011-01-07 to 2011-01-07. Participants: Hrvoje Nikšić, Andreas Schwab, Junio C Hamano, Jakub Narebski.
Thread: https://gitlist.dev/t/26233

## Hrvoje Nikšić, 2011-01-07 18:56

Subject: 'git add' option to non-interactively stage working tree changes
Message-ID: <AANLkTimLKZnVn8Lr-E-8M8T5mXA55XabCT5rC+broeFJ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimLKZnVn8Lr-E-8M8T5mXA55XabCT5rC%2BbroeFJ%40mail.gmail.com

```
Is there a way to non-interactively instruct git to stage all changes
in the working tree, specifically those that would be detected by "git
add -p" or "git commit -a"?

One can use "git add" for this purpose, but it is necessary to specify
the root, and with the unpleasant side effect of adding untracked
files. "git add -u" avoids the file addition, but root still has to be
spelled out. "git add -p" does exactly the right thing, but requires
interaction. I would like an automated --yes-to-all version of "git
add -p".

Specifying the root may seem innocuous, but it is inconsistent with
"git diff" and "git commit [-a]", which don't care where in the tree
you are.

```

## Andreas Schwab, 2011-01-07 19:52

Subject: Re: 'git add' option to non-interactively stage working tree changes
Message-ID: <m2aajcbiei.fsf@igel.home>
URL: https://gitlist.dev/e/m2aajcbiei.fsf%40igel.home
In-Reply-To: <AANLkTimLKZnVn8Lr-E-8M8T5mXA55XabCT5rC+broeFJ@mail.gmail.com>

```
Hrvoje Nikšić <hniksic@gmail.com> writes:

> Specifying the root may seem innocuous, but it is inconsistent with
> "git diff" and "git commit [-a]", which don't care where in the tree
> you are.

You can always use "$(git rev-parse --show-cdup)." as the root.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## Hrvoje Nikšić, 2011-01-07 20:03

Subject: Re: 'git add' option to non-interactively stage working tree changes
Message-ID: <AANLkTi=iwOGv3PzrRcVGDwwoTXmJ4CuC11vuYsjn4xxV@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DiwOGv3PzrRcVGDwwoTXmJ4CuC11vuYsjn4xxV%40mail.gmail.com
In-Reply-To: <m2aajcbiei.fsf@igel.home>

```
On Fri, Jan 7, 2011 at 8:52 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Hrvoje Nikšić <hniksic@gmail.com> writes:
>
>> Specifying the root may seem innocuous, but it is inconsistent with
>> "git diff" and "git commit [-a]", which don't care where in the tree
>> you are.
>
> You can always use "$(git rev-parse --show-cdup)." as the root.

Thanks for the tip. I'll note that this is not exactly easy to
discover, though, and it's quite some typing. Since git add -p and git
add -i seem capable of determining the root themselves, maybe there
should be a way to do the same for -u? Or even make it the default?

```

## Junio C Hamano, 2011-01-07 20:44

Subject: Re: 'git add' option to non-interactively stage working tree changes
Message-ID: <7vfwt45tqv.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfwt45tqv.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTi=iwOGv3PzrRcVGDwwoTXmJ4CuC11vuYsjn4xxV@mail.gmail.com>

```
Hrvoje Nikšić <hniksic@gmail.com> writes:

> Thanks for the tip. I'll note that this is not exactly easy to
> discover, though, and it's quite some typing. Since git add -p and git
> add -i seem capable of determining the root themselves, maybe there
> should be a way to do the same for -u? Or even make it the default?

The general design principle when talking about an operation to build
towards the next commit is to limit the operation to the current working
directory when working from a subdirectory, so I would have to say that
what -p and -i do is wrong, but this is already a very well established
behaviour and there is no way to change the default (the same thing can be
said for what -u does).

I think it might be Ok to introduce a --full-tree option to "git add" (and
"git grep"), though.  But introduction of corresponding configuration
variable to flip the default needs to be done carefully in steps across
major version boundaries as usual (i.e. first introduce --no-full-tree,
wait for 9 to 12 months to make sure scripts are updated, then start
honoring add.fullTree and grep.fullTree configuration variables).

```

## Jakub Narebski, 2011-01-07 23:50

Subject: Re: 'git add' option to non-interactively stage working tree changes
Message-ID: <m3pqs8b7fj.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3pqs8b7fj.fsf%40localhost.localdomain
In-Reply-To: <7vfwt45tqv.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> I think it might be Ok to introduce a --full-tree option to "git add" (and
> "git grep"), though.  But introduction of corresponding configuration
> variable to flip the default needs to be done carefully in steps across
> major version boundaries as usual (i.e. first introduce --no-full-tree,

You meant --relative[1] here (instead of --no-full-tree), didn't you?

[1] Supported by diff, and in a way by git-diff-tree
-- 
Jakub Narebski
Poland
ShadeHawk on #git

```
