From 46af2f08b3e8b571648c280715293d678143cb02 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 20 May 2021 20:30:05 +0200 Subject: [PATCH] =?UTF-8?q?Add=20Example=20for=20=E2=80=94amend=20to=20REA?= =?UTF-8?q?DME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #159 --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index cb99f27..a590572 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,41 @@ Using command lines options needs to be done manually for each workflow which yo - [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) +## Using `--amend` and `--no-edit` as commit options + +If you would like to use this Action to create a commit using [`--amend`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend) and [`--no-edit`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-edit) you need to make some adjustments. + +**☝️ Important Notice:** You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase) + +First, you need to extract the previous commit message by using `git log -1 --pretty=%B`. +Then you need to provide this last commit message to the Action through the `commit_message` input option. + +Finally, you have to use `push_options: '--force'` to overwrite the git history on the GitHub remote repository. (git-auto-commit will not do a `git-rebase` for you!) + +The steps in your workflow might look like this: + +```yaml +- uses: actions/checkout@master + with: + fetch-depth: 2 + +# Other steps in your workflow to trigger a changed file + +- name: Get last commit message + id: last-commit-message + run: | + echo "::set-output name=msg::$(git log -1 --pretty=%B)" + +- uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: ${{ steps.last-commit-message.outputs.msg }} + commit_options: '--amend --no-edit' + push_options: '--force' + skip_fetch: true +``` + +See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details. + ## Troubleshooting ### Action does not push commit to repository