How do I move an unstaged file to untracked?

6.9k views Asked by At

Say this is what I'm looking at in git status:

Changes not staged for commit:
    modified:   Makefile.in

Untracked files:
   ../node_modules/somepath/inverter_packet.js

What I want to do is something like move Makefile.in from 'Changes not staged for commit' to 'Untracked files.'

I know I can ignore changes with git update-index --assume-unchanged Makefile.in, and get them back with the --no-assume-unchanged command, but I'd rather not have these files completely out-of-view, because I do edit/commit them once in a while.

I want to remove files from the 'not staged' section, but still see it when I type git status.

Alternately, if I could (preferably simply) stop showing the diff for unstaged files (e.g. like my Makefile.in up there) when typing git diff, that would also be good.

2

There are 2 answers

1
Yuval Adam On BEST ANSWER

I want to remove files from the 'not staged' section, but still see it when I type git status.

Where do you want them moved to? There really are no other places to hide.

As you mentioned, these are tracked files, so you don't want to remove them from the repo with git rm, that would be plain wrong. The only real option here is to have them assumed unchanged. They'll be "out of view" either way, so the question doesn't really make much sense.

One other option is to stash only that single file using git stash -p but then you'll lose the changes in your working copy until you pop the stash back, which again, is not what it seems you're going after.

0
rajStack On

I faced similar situation. Here is what I followed to make unstaged to untracking.

  1. git rm [FileName and path] --cached

Now corresponding File is deleted. It keeps the file in localhost with --cached option

  1. git commit (the deleted files).

Build your project again. You will get the File in Untracked if it is generated always. Now add it in .git/info/exclude.

  1. git status

You are now untracking the initially unstaged file.

Note: You will not get the files in untracking if they are not generated during build. I mean they are removed from git tracking totally.