My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Saturday, February 28, 2026

How To undo a git add operation (unstage files)

To undo a git add operation (unstage files), the recommended command is git restore --staged. This moves changes from the staging area back to the working directory without losing any modifications.

Recommended Method: git restore --staged
This command is the preferred method in modern Git (versions 2.23+) because it is more intuitive and safer for this specific task.
  • Unstage a specific file:
    bash
    git restore --staged <filename>
    
    (Replace <filename> with the actual name of your file, e.g., git restore --staged index.html).
  • Unstage all files:
    bash
    git restore --staged .
Alternative Method: git reset
Before git restore was introduced, the git reset command was used to unstage files, and it still works.
  • Unstage a specific file:
    bash
    git reset <filename>
    
  • Unstage all files:
    bash
    git reset

No comments:

Post a Comment