Skip to content

docs(git-workflow): warn about destructive checkout and identical hunks - #138

Merged
CybotTM merged 2 commits into
mainfrom
feat/retro-checkout-and-identical-hunks
Aug 5, 2026
Merged

docs(git-workflow): warn about destructive checkout and identical hunks#138
CybotTM merged 2 commits into
mainfrom
feat/retro-checkout-and-identical-hunks

Conversation

@CybotTM

@CybotTM CybotTM commented Aug 5, 2026

Copy link
Copy Markdown
Member

Came from /retro: yes

Three reference-only additions, all from one session of parallel PR work.

git checkout <ref> -- <path> is destructive and leaves no reflog entry (advanced-git.md). Used to restore a file after measuring a baseline against develop, it silently discarded a fix that was still only in the working tree — and the next git add committed the file without it. The section it lands in already documents git show <ref>:<path>, which is the non-destructive answer, so this only names the trap and points at the tool already described above it.

Chaining git push behind a filtered test run with && pushes on a red suite (advanced-git.md). grep -E 'OK|FAILURES' exits 0 on matching the word FAILURES, so the chain reads the filter's status, not the runner's. Includes the verification step that actually catches it: fetch the branch back and grep the pushed blob.

While writing this PR the same class of failure happened again in this repo — the end-of-file-fixer hook aborted the commit, the &&-chained push ran anyway and created a remote branch pointing at the unchanged base. The fix that landed is therefore also the demonstration.

Two independent PRs needing the same hunk can carry it byte-identically (pull-request-workflow.md). Git merges the same change at the same place once, in any order, so the merge-order constraint disappears instead of the PRs having to be stacked. Includes the byte-comparison and the throwaway-clone check that proves the property rather than assuming it.

No SKILL.md change, so the 500-word budget is untouched.

Three lessons from one session, all reference-only:

`git checkout <ref> -- <path>` overwrites the working tree with no
warning and no reflog entry. Used to restore a file after measuring a
baseline, it silently discarded an uncommitted fix, and the following
commit went out without it. `git show <ref>:<path>` already documented
just above is the non-destructive answer.

Chaining `git push` behind a filtered test run with `&&` pushes on a
red suite, because grep exits 0 on matching the word FAILURES.

Two independent PRs that both need the same hunk can carry it
byte-identically, which git merges once in any order. That removes the
merge-order constraint instead of stacking the PRs.

Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
Copilot AI lite review requested due to automatic review settings August 5, 2026 08:22
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions github-actions Bot added documentation Improvements or additions to documentation skill labels Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Git workflow reference documentation to warn about a few easy-to-miss failure modes encountered during parallel PR work, and adds a conflict-resolution technique for handling identical hunks across independent PRs.

Changes:

  • Add guidance on avoiding destructive git checkout <ref> -- <path> when work is uncommitted, with safer alternatives (git show, worktrees).
  • Document why &&-chaining a git push behind filtered test output can push even when the suite fails, plus a remote verification step.
  • Add a “byte-identical hunk in both PRs” strategy to remove merge-order constraints when two PRs need the same change.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
skills/git-workflow/references/pull-request-workflow.md Adds a conflict-resolution pattern for duplicating identical hunks across independent PRs and verifying merge behavior.
skills/git-workflow/references/advanced-git.md Adds warnings and safer patterns around destructive path checkout and &&-chained push pipelines, plus a small cleanup at EOF.
Suppressed comments (1)

skills/git-workflow/references/advanced-git.md:936

  • Same issue as above: develop is repo-specific. Use a placeholder baseline ref so the command can be copied verbatim into repos that don’t have a develop branch.
git worktree add /tmp/baseline develop

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread skills/git-workflow/references/advanced-git.md Outdated
Comment thread skills/git-workflow/references/advanced-git.md Outdated
Comment thread skills/git-workflow/references/pull-request-workflow.md Outdated
Comment thread skills/git-workflow/references/pull-request-workflow.md Outdated
Comment thread skills/git-workflow/references/pull-request-workflow.md Outdated
Comment thread skills/git-workflow/references/advanced-git.md Outdated
Comment thread skills/git-workflow/references/advanced-git.md Outdated
- The merge-order loop continued after a conflict, leaving the repo
  mid-merge and every later result meaningless. Abort and exit instead.
- grep -c counts lines, so a multi-line pattern never matches: say to
  use one distinctive line, and -F to avoid regex surprises in code.
- set -o pipefail is not in POSIX sh; lead with the portable rc capture
  and note where pipefail applies.
- "nothing to recover from" was absolute; uncommitted content never
  reaches the object store, but an editor history or snapshot may hold it.
- Replace the hardcoded develop with <base-ref>, and use consistent
  placeholders in the sed extraction.

Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@CybotTM
CybotTM requested a lite review from Copilot August 5, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CybotTM
CybotTM merged commit 52ecc1f into main Aug 5, 2026
21 of 22 checks passed
@CybotTM
CybotTM deleted the feat/retro-checkout-and-identical-hunks branch August 5, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants