Author:
Ignore Tracked Files⚓︎
We are going to use
git rm -r --cached <file path>here.
Ignore file back⚓︎
When the files are tracked, directly ignoring them in the git ignore doesn't work. The correct steps are:
-
Remove index
-
Update gitignore
Refresh index⚓︎
You can also use this command to refresh the tracking of the file.
Will this affect the time stamp of the tracked file?
Someone might be curious: will this tracking refreshment affect the timestamp of the file?
The answer is no. Below is a table that can be helpful to explain what it does.
| Aspect | Does git rm --cached care? |
Explanation |
|---|---|---|
| Git index (staging area) | ✅ Yes | Primary target: paths are removed from the index |
| File paths | ✅ Yes | Tells Git these paths should no longer be tracked |
| Current commit diff | ✅ Yes | Appears as deleted in the next commit |
| Permanent removal from repo | ⚠️ Depends on usage | Permanent only if not re-added with git add |
| Working tree files (disk) | ❌ No | Files remain on disk |
| File content | ❌ No | Contents are not modified |
| Existing Git commits | ❌ No | Past commits and history are untouched |
| Rename / move history tracking | ❌ No | History can still be associated via content similarity |
| MkDocs git-revision-date plugins | ❌ (Indirect) | Git-based timestamps usually remain intact |
| OS file timestamps (mtime/ctime) | ❌ No | Git ignores filesystem timestamps |
| Remote repository | ❌ No | No effect until commit and push |
Restore the change⚓︎
- Case 1: Already executed
git rm -r --cached docsbut have not committed yet ->git restore --staged docs. - Case 2: Have committed, but have not pushed ->
git reset --soft HEAD~1.