mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Keep File Locally With git rm as a Git TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1345 TILs and counting..._
|
||||
_1346 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -283,6 +283,7 @@ _1345 TILs and counting..._
|
||||
- [Include Some Stats In Your Git Log](git/include-some-stats-in-your-git-log.md)
|
||||
- [Intent To Add](git/intent-to-add.md)
|
||||
- [Interactively Unstage Changes](git/interactively-unstage-changes.md)
|
||||
- [Keep File Locally With `git rm`](git/keep-file-locally-with-git-rm.md)
|
||||
- [Last Commit A File Appeared In](git/last-commit-a-file-appeared-in.md)
|
||||
- [List All Files Changed Between Two Branches](git/list-all-files-changed-between-two-branches.md)
|
||||
- [List Branches That Contain A Commit](git/list-branches-that-contain-a-commit.md)
|
||||
|
||||
20
git/keep-file-locally-with-git-rm.md
Normal file
20
git/keep-file-locally-with-git-rm.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Keep File Locally With `git rm`
|
||||
|
||||
Let's say I've added a new file `data.json` to my repo as part of the most
|
||||
recent commit. I realize this isn't the point at which I want to add that file.
|
||||
So, I do `git rm data.json` and then `git commit --amend` to rework that
|
||||
commit.
|
||||
|
||||
However, when I look in my working tree, or even just my file system, I'll
|
||||
notice that `data.json` is gone. The `git rm` command completely removed the
|
||||
file since it was previously an untracked file.
|
||||
|
||||
To keep `git rm` from tossing out my file like that, I can include the
|
||||
`--cached` flag which will remove the file from the index (stages it to be
|
||||
`deleted`), but restore it to the working directory.
|
||||
|
||||
```bash
|
||||
$ git rm --cached data.json
|
||||
```
|
||||
|
||||
See `man git-rm` for more details on the `--cached` flag.
|
||||
Reference in New Issue
Block a user