Forrest logo
back to the git tool

git-am:tldr:fd876

git-am: Apply as much of a patch file as possible, saving failed hunks to reject files.
$ git am --reject ${filename-patch}
try on your machine

The git am --reject ${filename-patch} command is used in Git to apply a patch file to a branch but in case of conflicts, it automatically generates a .rej file containing rejected hunks.

Here's what each part of the command means:

  • git am: It is the command used to apply a series of patches stored in a mailbox format to a branch in the repository.

  • --reject: It is an option used with the git am command. When a patch can't be directly applied due to conflicts with the existing code, this option causes Git to generate a .rej file that contains the rejected patch hunks.

  • ${filename-patch}: It represents the path to the patch file that you want to apply to your branch within the Git repository. You need to replace ${filename-patch} with the actual name and path of the patch file.

When you run this command, Git attempts to apply the patch to the branch. If the patch can be applied cleanly, it is directly applied. However, if there are conflicts with the existing code, the command will generate a .rej file for each rejected hunk in the patch. The .rej file contains the rejected code that couldn't be merged automatically.

The .rej file allows you to manually review and modify the rejected changes before reattempting to apply the patch. It helps in resolving conflicts and ensuring that the patch is correctly applied to the branch while dealing with any possible code conflicts.

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