-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a97e0f
commit 2659fd9
Showing
4 changed files
with
52 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file was deleted.
Oops, something went wrong.