2018-03-17 18:26:18 +05:30
|
|
|
---
|
|
|
|
comments: false
|
|
|
|
---
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Unstage
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
## Unstage
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
- To remove files from stage use reset HEAD. Where HEAD is the last commit of the current branch.
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
```bash
|
|
|
|
git reset HEAD <file>
|
|
|
|
```
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
- This will unstage the file but maintain the modifications. To revert the file back to the state it was in before the changes we can use:
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
```bash
|
|
|
|
git checkout -- <file>
|
|
|
|
```
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
----------
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
- To remove a file from disk and repo use 'git rm' and to rm a dir use the '-r' flag:
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
```
|
|
|
|
git rm '*.txt'
|
|
|
|
git rm -r <dirname>
|
|
|
|
```
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
- If we want to remove a file from the repository but keep it on disk, say we forgot to add it to our `.gitignore` file then use `--cache`:
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
git rm <filename> --cache
|
|
|
|
```
|