Git Tutorial - Unstage Files

Jinku Hu Jun 25, 2020
Git Tutorial - Unstage Files

In this tutorial, we will demonstrate how to reset files from the staging area.

Unstage Files From Staging Area

After you have added some files to the staging area, you come to a situation that you don’t want to commit this change to the repository because you plan to do more modification on this file, then you need to unstage the file from the staging area. The file change is still in the staging area if you check the git status, and it could be reset with the command git reset HEAD <file>....

Le’t check with our working copy status,

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	renamed:    test1_rename.txt -> move/test1.txt

We want to unstage this rename, then,

$ git reset HEAD
Unstaged changes after reset
D test1_rename.txtgi

The working copy status changes to

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	deleted:    test1_rename.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	move/

no changes added to commit (use "git add" and/or "git commit -a")

It is back to the status before the rename is staged.

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook