# git add -N vs. git stash

2 messages from 2022-08-08 to 2022-08-08. Participants: Uwe Kleine-König, Junio C Hamano.
Thread: https://gitlist.dev/t/58279

## Uwe Kleine-König, 2022-08-08 16:39

Subject: git add -N vs. git stash
Message-ID: <20220808163954.tnozlrv7nyx63imu@pengutronix.de>
URL: https://gitlist.dev/e/20220808163954.tnozlrv7nyx63imu%40pengutronix.de

```
Hello,

somehow git stash doesn't understand the index after git add -N:

	$ git version
	git version 2.36.1

	$ git init -q

	$ echo foo > foo

	$ git add foo

	$ git commit -a -m .
	[main (root-commit) 0e4b48cb4913] .
	 1 file changed, 1 insertion(+)
	 create mode 100644 foo

	$ echo bar > bar

	$ git add -N bar

	$ git stash push
	error: Entry 'bar' not uptodate. Cannot merge.
	Cannot save the current worktree state

I'd say that's not a feature, is it?

I would have expected the last command to just remove bar from the
index.

Best regards
Uwe

```

## Junio C Hamano, 2022-08-08 17:30

Subject: Re: git add -N vs. git stash
Message-ID: <xmqqh72mskvi.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqh72mskvi.fsf%40gitster.g
In-Reply-To: <20220808163954.tnozlrv7nyx63imu@pengutronix.de>

```
Uwe Kleine-König <uwe@kleine-koenig.org> writes:

> I'd say that's not a feature, is it?

I think that is a sign that "add -N" came much later than "stash",
and whoever added the former was not a heavy user of "stash" ;-)

As the state of the "tracked files in the working tree" and "staged
contents in the index" are both stored as tree objects, I think the
necessary fix would involve

 - record the contents of the "intent-to-add" paths to the tree
   object for the working tree.

 - record the fact that the "intent-to-add" paths are "not in the
   index yet" by removing them from the tree object for the index.

on the recording side (i.e. "stash create"), and then teach the
replay side (i.e. "stash apply") to pay attention to such strange
"exists in the tree for the working tree, but missing from the tree
for the index" paths and mark them with the "intent-to-add" bit.



```
