After I made a commit, I want to clean the stage area. Here is what I did:
git add 1.txt ----- stage the 1.txt file
git commit -m "commit 1.txt" ----- commit the 1.txt file
git reset HEAD 1.txt ----- I want to clean the stage area
Then I check the stage area with this command:
git ls-files
The 1.txt is still shown.
Why?
Short answer:
Your staging is clean, atleast wrt HEAD if not the working directory too, once you commit.
Long answer:
You have committed the file
1.txt. When you commit the index (staging) and HEAD become the same. And when you dogit reset HEAD 1.txt, it is basically a noop, as both index and HEAD have the same version of 1.txt.And
git ls-fileswill display1.txtbecause the file is in your repo.Not really sure what you are trying to do. But once you have committed a file, you can unstage the modifications you have done to it. In the case of a newly added file, unstaging the modifications is the same as removing the newly added file from index and hence unstaging it. But that is not the same for a file already in the repo.
Ideal way to remove file from staging, is
git rm --cached– and when you commit, you remove the file from the repo as well. Remember that staging is the view of what HEAD will be once you commit.But I think
git rm --cachedis not what you want to do as you just want a clean staging / index. After you commit it is clean anyway ( atleast wrt HEAD if not the working directory).