summaryrefslogtreecommitdiff
path: root/doc/university/training/topics/unstage.md
blob: da36a3218e5690f50bf9629ac755c3e1a824c1e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---
comments: false
---

# Unstage

----------

## Unstage

- To remove files from stage use reset HEAD. Where HEAD is the last commit of the current branch.

    ```bash
    git reset HEAD <file>
    ```

- 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:

    ```bash
    git checkout -- <file>
    ```

----------

- To remove a file from disk and repo use 'git rm' and to rm a dir use the '-r' flag:

    ```
    git rm '*.txt'
    git rm -r <dirname>
    ```

- 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`:

    ```
    git rm <filename> --cache
    ```