threads / discuss / 58279

git add -N vs. git stash

Subject: git add -N vs. git stash

## tl;dr

2 messages between Aug 8, 2022 and Aug 8, 2022.

replies: 1people: 2as markdown or json

Uwe Kleine-König· Aug 8, 2022, 16:39 UTC · lore
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· Aug 8, 2022, 17:30 UTC · re: Uwe Kleine-König · lore

Re: git add -N vs. git stash

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.

← back to recent threads