I get an unexpected appearance of "dev/null" in my git status output after interactively adding a patch for a file that was renamed. I'm wondering if this is expected and there is some good reason for this behavior, or if this could be a bug.
Below is a simple illustration of how to reproduce this. In my real-world scenario, it's a bit more complicated and there's a good reason why I'm using git add -p, but I was able to boil it down to this minimal example:
$ git init test Initialized empty Git repository in /local_disk/tmp/test/.git/ $ cd test $ echo "foo" > foo $ git add foo $ git commit -m 'Add foo' [master (root-commit) 3643b5d] Add foo 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 foo $ mv foo bar $ git add -p diff --git a/foo b/foo index 257cc56..0000000 --- a/foo +++ /dev/null @@ -1 +0,0 @@ -foo Stage this hunk [y,n,q,a,d,/,e,?]? y $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # new file: dev/null # deleted: foo # # Changed but not updated: # (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # deleted: dev/null # # Untracked files: # (use "git add ..." to include in what will be committed) # # bar
What is with the "new file: dev/null" and "deleted file: dev/null"? I would expect this to result in exactly the same thing as if I had done:
$ mv foo bar $ git rm foo $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # deleted: foo # # Untracked files: # (use "git add ..." to include in what will be committed) # # bar
I am using Git version 1.6.5.5, and have also reproduced it in 1.6.5.4. I was unable to reproduce it in my Cygwin environment which has Git at version 1.6.1.2.
git mvis not equivalent, because it moves and adds the file at the same time. I am moving the file using just plainmv, and then usinggit add -pto add it.git mvis the 'proper' way to change a file's name. To delete a file you usegit rmand to move one you usegit mv, don't just move the file yourself and expect git to read your thoughts :)git mv, if I'm not mistaken, was added to appease the crowds that were clamoring for such a command. It doesn't do anything that simply moving the file and then adding it would do. git, in fact, does read your mind (well, actually it examines the differences and identifies the rename on its own). Git doesn't need, or want, you to tell it about such things.