Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unstage.md « git « topics « doc - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: beb5d05ecfc57646dd12d2cb48c7747df4c5ef69 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
stage: Create
group: Source Code
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
---

# Unstage a file in Git **(FREE ALL)**

When you _stage_ a file in Git, you instruct Git to track changes to the file in
preparation for a commit. To disregard changes to a file, and not
include it in your next commit, _unstage_ the file.

## Unstage a file

- To remove files from staging, but keep your changes:

  ```shell
  git reset HEAD <file>
  ```

- To unstage the last three commits:

  ```shell
  git reset HEAD^3
  ```

- To unstage changes to a certain file from HEAD:

  ```shell
  git reset <filename>
  ```

After you unstage the file, to revert the file back to the state it was in before the changes:

```shell
git checkout -- <file>
```

## Remove a file

- To remove a file from disk and repository, use `git rm`. To remove a directory, use the `-r` flag:

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

- To keep a file on disk but remove it from the repository (such as a file you want
  to add to `.gitignore`), use the `rm` command with the `--cache` flag:

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