Skip to content

Commit

Permalink
Merge stage and unstage snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Apr 14, 2024
1 parent 7a97e0f commit 2659fd9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
6 changes: 6 additions & 0 deletions content/redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2821,3 +2821,9 @@
- from: /git/s/delete-remote-branch
to: /git/s/delete-branch
status: 301!
- from: /git/s/stage-files
to: /git/s/stage-unstage-files
status: 301!
- from: /git/s/unstage-files
to: /git/s/stage-unstage-files
status: 301!
27 changes: 0 additions & 27 deletions content/snippets/git/s/stage-files.md

This file was deleted.

46 changes: 46 additions & 0 deletions content/snippets/git/s/stage-unstage-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: Add or remove files from the Git staging area
shortTitle: Stage or unstage files
type: story
language: git
tags: [commit]
cover: coconuts
excerpt: Learn how to effectively use Git's staging area, by adding or removing files from it.
dateModified: 2024-04-07
---

Git's **staging area** is used to prepare changes for a commit. You can add or remove files from the staging area to control which changes are included in the next commit.

## Stage files

Adding changes to the staging area is as simple as using the `git add <pathspec>` command, with an appropriate **filename or fileglob**. That way, you can add individual files, files with a specific extension, or all changes in the working directory.

```shell
# Usage: git add <pathspec>

git add "30seconds.txt"
# Add the file `30seconds.txt` to the staging area

git add src/*.json
# Add all files with a `.json` extension in the `src` directory

git add .
# Adds all changes to the staging area
```

## Unstage files

Subsequently, you can remove files from the staging area using the `git restore --staged <pathspec>` command. This command allows you to unstage individual files, files with a specific extension, or all changes in the staging area.

```shell
# Usage: git restore --staged <pathspec>

git restore --staged "30seconds.txt"
# Remove the file `30seconds.txt` from the staging area

git restore --staged src/*.json
# Remove all files with a `.json` extension in the `src` directory

git restore --staged .
# Remove all changes from the staging area
```
27 changes: 0 additions & 27 deletions content/snippets/git/s/unstage-files.md

This file was deleted.

0 comments on commit 2659fd9

Please sign in to comment.