git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Can't git stash after using git add -N

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 16, 2016, 11:09 UTC
Message-ID
<CACsJy8CtPAdJavKPLo3B-s-x5QVzAjNRqOM+MgbjpRbCOSGkXQ@mail.gmail.com>
In-Reply-To
<xmqqvb4n58ko.fsf@gitster.mtv.corp.google.com>
On Wed, Mar 16, 2016 at 11:51 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> Josh Triplett <josh@joshtriplett.org> writes:
>
>> As far as I can tell, if I run "git add -N" on a file, and then commit
>> without adding the file contents, it gets committed as an empty file.
>
> Is that true?  Git once worked like that in earlier days, but I
> think write-tree (hence commit) would simply ignore intent-to-add
> entries from its resulting tree.

We have at least one problem, probably because of the confusion in diff code (I haven't checked further), which may be fixed once i re-fix d95d728 (diff-lib.c: adjust position of i-t-a entries in diff - 2015-03-16)

> /tmp $ git init a
Initialized empty Git repository in /tmp/a/.git/
> /tmp $ cd a
> /tmp/a $ git ci --allow-empty -m 1
[master (root-commit) 4d8aed4] 1
> /tmp/a $ git add -N new
fatal: pathspec 'new' did not match any files
So far so good..
> /tmp/a $ touch new
> /tmp/a $ git add -N new
OK let's delete "new" and trigger this problem
> /tmp/a $ rm new
> /tmp/a $ git ci -m NOOOO
[master ce2e4bb] NOOOO
> /tmp/a $ git cat-file commit HEAD|grep ^tree
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
> /tmp/a $ git cat-file commit HEAD^|grep ^tree
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904

The second commit should not be created. git-commit is somehow fooled that there's changes to commit.

-- 
Duy
Previous: Junio C HamanoNext: Josh Triplett
Message 5 of 9 in “Can't git stash after using git add -N”
  1. Josh TriplettMar 15, 2016
  2. Junio C HamanoMar 15, 2016
  3. Josh TriplettMar 16, 2016
  4. Junio C HamanoMar 16, 2016
  5. Duy NguyenMar 16, 2016
  6. Josh TriplettMar 16, 2016
  7. Jeff KingMar 16, 2016
  8. Junio C HamanoMar 16, 2016
  9. Jeff KingMar 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.