debian-mirror-gitlab/doc/topics/git/unstage.md
2021-06-08 01:23:25 +05:30

909 B

stage group info comments
none unassigned To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments false

Unstage

  • To remove files from stage use reset HEAD where HEAD is the last commit of the current branch. This unstages the file but maintain the modifications.

    git reset HEAD <file>
    
  • To revert the file back to the state it was in before the changes we can use:

    git checkout -- <file>
    
  • To remove a file from disk and repository, use git rm. To remove a directory, 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