1

I've untracked a file using this command:

git rm --cached source/html/weekend-message.html

This is the method described in this answer on Stack Overflow. After that, my git status looked like this:

enter image description here

I wasn't sure what to do now (I want a clean status), so I continued looking and found this answer and performed this command:

git reset HEAD source/html/weekend-message.html

Now my git status looks like this:

enter image description here

I am very confused. I just want to untrack this file and have an empty git status after that. How do I do that?


Update: After performing the commands suggested in VonC’s answer below:

git rm --cached source/html/weekend-message.html
git commit -m "delete source/html/weekend-message.html"

my git status looks like this:

enter image description here

Git status still isn't clean :(

Community
  • 1
  • 1
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385

1 Answers1

3

You should have:

  • committed (in order to record the deletion)
  • added that file to your .gitignore, add and commit that change.

Since you have reset that file (undoing the deletion recorded in the index), you can try again:

git rm --cached source/html/weekend-message.html
git commit -m "delete source/html/weekend-message.html"

Then:

  • add the file to the .gitignore file (you will see that is disappear immediately from the git status output)
  • add and commit that .gitignore modification (second commit there)

Note: as suggested below in the comments, you can make just one commit:

  • git rm --cached source/html/weekend-message.html
  • add the file to the .gitignore file (you will see that is disappear immediately from the git status output), git add .gitignore. Note: now you get a proper git status, ready to be commited: enter image description here
  • git commit -m "delete and ignore source/html/weekend-message.html"

Note that to ignore a file locally (as opposed to record its deletion in the history of the repo), you can use:

git update-index --skip-worktree -- yourFile

Not commit needed there, and the file remains in the history.

See more at "Git - Difference Between 'assume-unchanged' and 'skip-worktree'".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've performed these commands, but git status still isn't clean. – Šime Vidas Sep 27 '14 at 14:12
  • Btw are you saying that 2 commits are required to perform this property? (`rm --cached`, then commit the deletion, then update .gitignore, and finally commit the updated .gitignore) – Šime Vidas Sep 27 '14 at 14:15
  • @ŠimeVidas yes, but as soon as you add that file to the .gitignore, it should disappear from the status. I have edited the answer to make the two commits more visible. – VonC Sep 27 '14 at 14:16
  • Wow! I am a Git n00b, but having 2 commits in the history - "untrack foo" and "update .gitignore" - seems stupid. Is it really not possible to perform all this in a single commit? – Šime Vidas Sep 27 '14 at 14:21
  • @ŠimeVidas absolutely, that is actually a good idea. I was just breaking down the steps. – VonC Sep 27 '14 at 14:23
  • 1
    Instead of using an ignore file, if this is temporary (you might want to untrack the file and keep it around for reference, but not need an exception forever), just ignore that 'untracked files' section, or use `$ git status -uno` if you really want a "clean status". – Félix Saparelli Sep 27 '14 at 14:30
  • I've added the proper screenshot. Hallelujah! – Šime Vidas Sep 27 '14 at 14:30