Forrest logo
back to the git tool

git-add:tldr:23100

git-add: Interactively stage parts of a given file.
$ git add -p ${filename}
try on your machine

The command git add -p ${filename} in Git is used to add changes in a specific file interactively.

Here is a breakdown of the command:

  • git: It is the command for invoking Git, the version control system.

  • add: The add command is used to add changes to the staging area in Git.

  • -p: The -p flag stands for patch and is used to interactively add changes to the staging area. It allows you to review and select specific changes from a file before adding them.

  • ${filename}: The ${filename} is a placeholder for the name of the file you want to add changes from. You replace it with the actual filename you want to interactively add changes for.

When you run this command, Git will show you each change made in the specified file, one by one, and prompt you for action. You have options to add the change to the staging area, skip the change, split the change into smaller parts, etc. This command is useful when you want to be selective about which changes to include in your commit.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool