Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions plugins/git/commands/cherry-pick-by-patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
argument-hint: <commit_hash>
description: Cherry-pick git commit into current branch by "patch" command
---

## Name
git:cherry-pick-by-patch

## Synopsis
```
/git:cherry-pick-by-patch commit_hash
```

## Description

The `/git-cherry-pick-by-patch commit_hash` command cherry-picks commit with hash
`commit_hash` into current branch. Rather then doing `git cherry-pick commit_hash`,
the command streams the output of `git show commit_hash` to
`patch -p1 --no-backup-if-mismatch`, and then commit changes with commit message
from `commit_hash` commit.

## Workflow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are calling this ##Implementation by convention where workflow could be ###


### Pre-requisites

The commit with hash `commit_hash` must exist. To verify that use:
```bash
git show commit_hash
```
and check if exit code is zero.

Fail, if there is no `commit_hash` in the current repository checkout.

### Cherry-pick `commit_hash` into current branch

1. Execute command
```bash
git show commit_hash | patch -p1 --no-backup-if-mismatch
```
and check if exit code is zero. Fail if exit code is not zero.

2. Find files removed from local checkout by the patch command and execute `git rm` for them.

3. Find files added or modified by the patch command and execute `git add` for them.

4. Commit changes by `git commit` command and use commit title and description from `commit_hash` commit.

## Arguments

- **$1** (required): Commit hash (e.g., `902409c0`) of commit to cherry-pick.