Reputation: 1199
When I run git add --intent-to-add .
all untracked files changed their state from "Untracked files" (git status -s
showed ??
) to "Changes not staged for commit" (git status -s
now shows A
). Now, whenever I run git diff
I see the new files, too. How do I revert these state changes so that they become "untracked" again?
Upvotes: 11
Views: 1886
Reputation: 158
git reset --mixed
will reset all the files in the index (without doing anything to the actual files).
If you want to apply it to specific files, you can git reset --mixed <file>
, but it says this is deprecated and to use git reset -- <file>
for this purpose.
This certainly works in the specific case of removing a new file from the index which has been added with git add --intent-to-add
. It leaves the file itself as it was - git status
lists the file as untracked.
It's a bit like git restore --staged <file>
for files that are already tracked.
Upvotes: 3
Reputation: 1199
Use git reset --mixed
for this.
After --intent-to-add
, the file will be placed in the index but without its content. You want to remove it from the index without changing it in the working tree. That is precisely what git reset --mixed
does.
$ echo "some content.txt" > file.txt
$ git status ; echo "###" ; git status -s
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
###
?? file.txt
# This will add the file to the index but without its content.
# Hence, for Git all the content has "changed".
$ git add --intent-to-add .
$ git status ; echo "###" ; git status -s
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
new file: file.txt
no changes added to commit (use "git add" and/or "git commit -a")
###
A file.txt
$ git diff # show the content of file.txt
# Resets the index so that file.txt becomes completely new for Git.
$ git reset --mixed
$ git status ; echo "###" ; git status -s
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
###
?? file.txt
$ git diff # doesn't show the content of file.txt
Note that you can use -N
for git reset --mixed
to specifically not remove untracked files from the index.
Upvotes: 12