Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to work with patches #3580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ We do not capitalize the following terms:
* Red Hat subscription manifest
* subscription

## Working with patches

You can create patches to simplify sharing proposed changes compared to comments and suggestions on GitHub.

### Creating patches

1. Fetch the PR from GitHub:

$ git fetch upstream pull/1234/head:pr_1234_optional_description
Copy link
Member

Choose a reason for hiding this comment

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

With https://cli.github.com/ you can do gh pr checkout 1234 to check out a PR


2. Make your changes and commit them:

$ vim guides/common/modules/X
$ git add guides/common/modules/X
$ git commit -m "Proposed patch"

3. View the patch:

$ git show
Copy link
Member

Choose a reason for hiding this comment

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

There's also git format-patch:

$ gh pr checkout 3580
From https://github.com/theforeman/foreman-documentation
 * [new ref]                   refs/pull/3580/head -> how-to-apply-patch
Switched to branch 'how-to-apply-patch'
$ vi CONTRIBUTING.md 
$ git commit -am 'Use gh pr checkout'
[how-to-apply-patch 2a8be45942a4] Use gh pr checkout
 1 file changed, 2 insertions(+), 2 deletions(-)
$ git status
On branch how-to-apply-patch
Your branch is ahead of 'upstream/pr/3580' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
$ git format-patch upstream/pr/3580
0001-Use-gh-pr-checkout.patch

And you have a regular file (or files in case of multiple commits)


4. Email that patch or post it on GitHub.

### Applying patches

1. Store the patch in your `foreman-documentation` repository.
Copy link
Member

Choose a reason for hiding this comment

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

Technically the location doesn't matter so you can say /path/to/proposed.patch

2. Apply the patch:

$ git apply proposed.patch
Copy link
Member

Choose a reason for hiding this comment

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

If you used git format-patch you can use git am which also respects the metadata in the created patch.


3. Delete the file:

$ rm proposed.patch

4. Commit the patch to your branch:

$ git add guides/common/modules/X
$ git commit -m "Proposed patch"

To be extra nice, credit the person that provided the patch in the commit message.
Comment on lines +121 to +126
Copy link
Member

Choose a reason for hiding this comment

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

As noted before, when using git am, it already creates the commit with proper credit (because it respects the metadata).


## Further Information

* [Contributing Guidelines for Github documentation](https://github.com/github/docs/blob/main/CONTRIBUTING.md)
Expand Down
Loading