본문으로 건너뛰기
cccskills
무료GitHub에 공개

git-separate-tangled-changes-into-prs

Separate a messy working tree with multiple tangled features into clean, focused PRs. Use when: (1) Working tree has uncommitted changes from multiple features mixed together, (2) Need to create a PR for just one feature from a mixed working tree, (3) "git stash pop" fails with "already exists, no checkout" for untracked files, (4) Pre-commit hooks block commits due to unrelated untracked files with errors, (5) Interface changes in one feature break consumer files from another feature in the same working tree. Covers git stash workflows, branch separation, conflict resolution, and pre-commit hook workarounds. Never stack PRs — always target main.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md9.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Separating Tangled Changes into Clean PRs

Problem

A working tree accumulates uncommitted changes from multiple features over time. When you need to create focused PRs, the changes are tangled together — some files have changes from multiple features, generated files (like .mocks.dart) reflect all features combined, and pre-commit hooks fail on unrelated WIP code.

Context / Trigger Conditions

  • Working tree has 50+ modified/untracked files spanning multiple features
  • git diff --name-only shows files from clearly different features
  • You need to create a PR for Feature A but Feature B's files cause analysis errors
  • Pre-commit hooks run dart analyze / eslint / etc. on ALL files (not just staged), so untracked WIP files block commits
  • Some files have changes from BOTH features (mixed-change files)

Solution

Step 1: Stash Everything Safely

git stash -u -m "descriptive-name-for-safety"

The -u flag includes untracked files. This is your safety net.

Step 2: Create Clean Feature Branch

git checkout main  # or the appropriate base
git pull
git checkout -b feature/clean-branch

Step 3: Pop Stash and Handle Conflicts

git stash pop

Common issue: "already exists, no checkout" — happens when untracked files from the stash already exist in the working tree. The tracked file changes still apply, but the stash is preserved (not dropped). This is safe; the files you need are already there.

Merge conflicts: Resolve each one. For files belonging to OTHER features, take the base version:

git checkout --theirs path/to/other-feature-file.dart

For files belonging to THIS feature, take the stash version or resolve manually.

Step 4: Handle Mixed-Change Files

Some files have changes from BOTH features. For these:

  1. Restore to the base version: git checkout main -- path/to/file.dart
  2. Re-apply ONLY your feature's changes manually (usually just import changes or a few lines)

Step 5: Deal with Pre-Commit Hooks That Check All Files

If your pre-commit hook analyzes ALL files (not just staged), untracked WIP files from other features will block your commit.

Workaround: Temporarily move problematic untracked files:

mkdir -p /tmp/other-features-backup
mv lib/unrelated_feature/ /tmp/other-features-backup/
mv test/unrelated_feature/ /tmp/other-features-backup/

Commit, then restore:

cp -r /tmp/other-features-backup/* .

Step 6: Regenerate Generated Files

If the project uses code generation (Mockito, Riverpod, Freezed, etc.), restore generated files to base and regenerate:

git checkout main -- **/*.mocks.dart **/*.g.dart
dart run build_runner build --delete-conflicting-outputs

This ensures generated files only reflect YOUR feature's changes.

Step 7: Fix Interface Break Cascades

When Feature A changes an interface (renames a method, changes parameter types), consumer files that weren't modified by Feature A will break. The analyzer catches these. Fix them before committing.

Common pattern:

  • Provider state changed CompleteParameters? to Map<String, dynamic>
  • Canvas widget still calls .colorFilters on what's now a Map
  • Fix: Update the consumer to use the new interface

Step 8: Do NOT Stack PRs — Combine Dependent Features Into One PR

Never create a PR that targets another PR's branch instead of main. Stacked PRs cause real problems in this project: rebases cascade, reviewer context fragments, merge order becomes load-bearing, CI runs against the wrong base, and "fix on parent" forces a re-review of the child.

If Feature B depends on Feature A, ship them as ONE combined PR.

# Both features live on a single branch, targeting main
git checkout main && git pull
git checkout -b feature-a-and-b
# ... commit Feature A changes ...
# ... commit Feature B changes (separate commits are fine) ...
gh pr create --base main  # one PR, both features

Write the PR description so the two features are clearly delineated — separate sections, separate test plans. Reviewers can read it as a single unit, and the merge story is one click. This is the default when changes are interdependent.

The only time to split is when the features are truly independent — in which case they each get their own PR targeting main, in any order. If you find yourself wanting "B based on A," that's the signal to combine them, not to stack.

Verification

  1. git diff main...HEAD --stat shows only files for YOUR feature
  2. dart analyze (or equivalent) passes
  3. Tests pass
  4. Original stash still exists as safety net (if pop failed partially): git stash list

Example

Session where model-dedup changes and collaborator/watermark feature changes were tangled in 140+ modified files. The model-dedup work was independent of the collab/watermark feature, so they split cleanly:

  1. Stashed everything from fix/profile-copy-shares-url
  2. Created chore/model-deduplication from main, popped stash
  3. Separated model-dedup files, moved 16 untracked feature files to /tmp/
  4. Committed, pushed, created PR #1411 (target: main)
  5. Created feat/collabs-watermark-inspired-by from main, popped stash
  6. Fixed 3 interface breaks in video_editor_canvas.dart and video_metadata_preview_thumbnail.dart
  7. Committed, pushed, created PR #1412 (target: main — independent of #1411)

If the two features had been interdependent, they would have shipped as one combined PR — never stacked.

Alternative: Cherry-Pick Commits + Selective Stash Apply

When changes are split between commits AND stash (not just stash), use this approach instead:

# 1. Create branches from origin/main
git branch feature-a origin/main
git branch feature-b origin/main

# 2. Cherry-pick commits to appropriate branches
git checkout feature-a
git cherry-pick <commit-hash-for-feature-a>

# 3. Apply stashed files selectively (see gotchas below)

GOTCHA: Deleted Files in Stash

git checkout stash@{0} -- <path> FAILS for files that were DELETED in the stash — they don't exist in the stash tree. Handle deletions separately:

# For MODIFIED files — checkout from stash works
git checkout stash@{0} -- path/to/modified_file.dart

# For DELETED files — must use git rm instead
git rm path/to/deleted_file.dart

# Check which are deletions vs modifications first:
git stash show stash@{0} --name-status
# D = deleted (use git rm), M = modified (use checkout)

GOTCHA: Mono-Repo Stash Path Prefixes

When git root is a parent directory but you work in a subdirectory, stash paths include the subdirectory prefix:

# Working in: /project/mobile/
# Git root:   /project/
# Stash shows: mobile/lib/file.dart (NOT lib/file.dart)

# Must run checkout from repo root:
cd $(git rev-parse --show-toplevel)
git checkout stash@{0} -- mobile/lib/file.dart

GOTCHA: Cherry-Pick Produces Empty Commit

If a commit was already merged to main via a different PR (different hash), cherry-pick will produce an empty commit:

# "The previous cherry-pick is now empty"
git cherry-pick --skip  # Skip it, it's already on main

GOTCHA: Pre-Commit Hooks on Cherry-Picked Branches

When cherry-picking onto branches from origin/main, the analyzer may find pre-existing errors on main unrelated to your changes. Use --no-verify only when you've confirmed the errors aren't yours:

git commit --no-verify -m "feat: your changes"

Verify Completeness

Compare stash contents against all branch diffs:

git stash show stash@{0} --name-only | sort > /tmp/stash_files.txt
git diff --name-only origin/main..feature-a
git diff --name-only origin/main..feature-b
# Every stash file should appear in exactly one branch

Notes

  • Always stash with -u to capture untracked files
  • Never force-drop a stash until you've verified everything is safe
  • Mixed-change files are the hardest part — identify them early by checking which files have changes from multiple features
  • Pre-commit hooks that check all files (not just staged) are the biggest blocker. Know your project's hook behavior before starting.
  • Never stack PRs. Always target main. If features depend on each other, combine them into one bigger PR — see Step 8.
  • The stash is preserved when pop fails on untracked files — don't panic, your data is safe

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

divinevideo의 스킬 모두 보기

이 스킬의 문제 신고