I Have Multiple Changes But Only Want to Commit the Port UpdateβMy Git Partial Staging Journey
I changed my dev server port from 5173 to 5174 across three files, but I also had other unrelated changes in those same files! π° I only wanted to commit the port changes. My mentor walked me through Git's partial staging features: git add -p, git stash, interactive staging, and patch mode. After some trial and error (and learning what NOT to do), I successfully committed only the port changes while keeping my other work-in-progress safe. This is professional Git workflow! π―
The Problem: Mixed Changesβ
Me (Backend Dev): I just fixed a port conflict by changing from 5173 to 5174 in three files:
vite.config.js(line 15)package.json(line 12)src/main/main.js(line 230)
But here's the problem: I also have other changes in main.js (new IPC handler), database.js, and App.jsx that aren't ready yet!
I want to commit ONLY the port changes. How do I do that?
The Git Status Reality Checkβ
Frontend Mentor: Let me first show you what Git sees:
git status
Output:
On branch main
Changes not staged for commit:
modified: package.json
modified: src/main/database.js
modified: src/main/main.js
modified: src/preload/index.js
modified: src/renderer/App.jsx
modified: vite.config.js
The challenge:
- β
vite.config.js- Only port change (safe to commit entirely) - β
package.json- Only port change (safe to commit entirely) - β οΈ
src/main/main.js- Port change PLUS new IPC handler (partial commit needed!) - β
database.js,preload/index.js,App.jsx- Only work-in-progress (skip entirely)
Understanding Git Staging Optionsβ
Me: Can't I just do git add vite.config.js package.json main.js?
Frontend Mentor: That would stage ALL changes in main.js, including your WIP code! We need more precision.
Git Staging Levelsβ
Git gives you three levels of control:
Level 1: Stage Entire Files (Too Coarse)β
git add vite.config.js package.json src/main/main.js
Result: β Stages the port change AND the IPC handler Problem: Commits unfinished work!
Level 2: Interactive Staging (Just Right!)β
git add -p src/main/main.js
Result: β Git asks you hunk-by-hunk which changes to stage Perfect! Stage port change, skip IPC handler
Level 3: Manual Patch Editing (Advanced)β
git add -e src/main/main.js
Result: β Opens editor to manually select lines Most precise, but complex!
The Journey: Trial and Errorβ
Me: Show me the journeyβincluding the mistakes!
Frontend Mentor: Absolutely! Here's the real process, mistakes and all:
Attempt 1: Simple git add (Failed)β
git add vite.config.js package.json src/main/main.js
git diff --cached
What happened:
diff --git a/src/main/main.js b/src/main/main.js
@@ -227,7 +227,7 @@
});
const rendererUrl = isDev
- ? 'http://localhost:5173'
+ ? 'http://localhost:5174' β β
Want this
: `file://${path.join(__dirname, '..', '..', 'dist', 'renderer', 'index.html')}`;
+// New IPC handler for database operations
+ipcMain.handle('database-query', async (event, query) => { β β Don't want this!
+ return await db.query(query);
+});
Problem: Staged both port change and IPC handler!
Fix: Reset and try again
git reset HEAD src/main/main.js
Attempt 2: Interactive Staging (Learning Curve)β
git add -p src/main/main.js
Git asks:
Stage this hunk [y,n,q,a,d,s,e,?]?
Me: Wait, what do these letters mean? π΅
Frontend Mentor: Here's the cheat sheet:
| Key | Action | When to Use |
|---|---|---|
y | Yes, stage this hunk | You want this change |
n | No, skip this hunk | You don't want this change |
s | Split into smaller hunks | Hunk has both wanted & unwanted changes |
e | Edit hunk manually | Need precise line control |
q | Quit (stop staging) | Made a mistake, start over |
? | Show help | Learn what each option does |
Attempt 3: Interactive Staging (Success!)β
git add -p src/main/main.js
Git shows first hunk (port change):
@@ -227,7 +227,7 @@
});
const rendererUrl = isDev
- ? 'http://localhost:5173'
+ ? 'http://localhost:5174'
: `file://${path.join(__dirname, '..', '..', 'dist', 'renderer', 'index.html')}`;
Stage this hunk [y,n,q,a,d,s,e,?]?
Me types: y β
(Yes, stage the port change)
Git shows second hunk (IPC handler):
@@ -850,6 +850,11 @@
});
});
+// New IPC handler
+ipcMain.handle('database-query', async (event, query) => {
+ return await db.query(query);
+});
+
app.on('window-all-closed', () => {
Stage this hunk [y,n,q,a,d,s,e,?]?
Me types: n β
(No, skip the IPC handler)
Result:
[main c977432] chore: change development server port from 5173 to 5174
3 files changed, 3 insertions(+), 3 deletions(-)
Perfect! Only port changes committed! π
The Complete Workflowβ
Me: Walk me through the complete workflow step-by-step.
Frontend Mentor: Here's the production-ready process:
Step 1: Check Current Statusβ
git status
Output:
Changes not staged for commit:
modified: package.json β Port change only
modified: src/main/database.js β WIP only
modified: src/main/main.js β Port change + WIP
modified: src/renderer/App.jsx β WIP only
modified: vite.config.js β Port change only
Step 2: Stage Files with Only Port Changesβ
git add vite.config.js package.json
Why: These files have only port changes, safe to stage entirely.
Step 3: Interactively Stage Partial Changesβ
git add -p src/main/main.js
Interactive session:
Hunk 1: Port change (5173 β 5174)
Stage this hunk? y β
Hunk 2: New IPC handler
Stage this hunk? n β
Hunk 3: Import statement
Stage this hunk? n β
Step 4: Verify Staged Changesβ
git diff --cached
Should show ONLY:
diff --git a/package.json b/package.json
@@ -9,7 +9,7 @@
"scripts": {
"dev": "cross-env NODE_ENV=development concurrently \"npm:dev:vite\" \"npm:dev:electron\"",
"dev:vite": "vite",
- "dev:electron": "wait-on tcp:5173 && electron . --enable-logging",
+ "dev:electron": "wait-on tcp:5174 && electron . --enable-logging",
"build": "rimraf dist && cross-env NODE_ENV=production vite build && electron-builder build --publish=never",
diff --git a/src/main/main.js b/src/main/main.js
@@ -227,7 +227,7 @@
});
const rendererUrl = isDev
- ? 'http://localhost:5173'
+ ? 'http://localhost:5174'
: `file://${path.join(__dirname, '..', '..', 'dist', 'renderer', 'index.html')}`;
diff --git a/vite.config.js b/vite.config.js
@@ -12,7 +12,7 @@
},
publicDir: path.resolve(__dirname, 'public'),
server: {
- port: 5173,
+ port: 5174,
strictPort: true
},
Perfect! Only port changes, no WIP code! β
Step 5: Create the Commitβ
git commit -m "chore: change development server port from 5173 to 5174
- Update Vite config to use port 5174
- Update package.json dev:electron script to wait for 5174
- Update main.js renderer URL to load from 5174
- Resolves port conflict with another service"
Step 6: Verify Commit Contentsβ
git log -1 --stat
Output:
commit c977432f8d93a54faf3af7fbbc528a70bbe30ab6
Author: Mahmut Salman <csmahmutsalman@gmail.com>
Date: Wed Oct 29 14:39:47 2025 +0300
chore: change development server port from 5173 to 5174
- Update Vite config to use port 5174
- Update package.json dev:electron script to wait for 5174
- Update main.js renderer URL to load from 5174
- Resolves port conflict with another service
package.json | 2 +-
src/main/main.js | 2 +-
vite.config.js | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
Perfect! Clean commit with only port changes! π―
Step 7: Check Remaining Changesβ
git status
Output:
Changes not staged for commit:
modified: src/main/database.js
modified: src/main/main.js β Still has IPC handler change
modified: src/renderer/App.jsx
Excellent! WIP changes remain unstaged for future commits! β
Advanced Technique: git stash for Temporary Isolationβ
Me: What if I want to temporarily hide my WIP changes to see only port changes?
Frontend Mentor: Great question! Use git stash:
The Stash Workflowβ
# Step 1: Stash WIP changes in specific files
git stash push -m "WIP: database and UI changes" \
src/main/database.js \
src/renderer/App.jsx
# Step 2: Now only port-related changes remain
git status
Output:
Changes not staged for commit:
modified: package.json
modified: src/main/main.js β Only port change now!
modified: vite.config.js
# Step 3: Stage and commit port changes
git add -A
git commit -m "chore: change dev server port from 5173 to 5174"
# Step 4: Bring back WIP changes
git stash pop
Result:
- β Port changes committed cleanly
- β WIP changes restored
- β No mixing of concerns!
Common Mistakes and How to Fix Themβ
Me: What mistakes should I avoid?
Frontend Mentor: Here are the classics!
Mistake 1: Staging Everythingβ
β WRONG:
git add .
git commit -m "chore: update port"
Problem: Commits ALL changes, including WIP code!
β
RIGHT:
git add vite.config.js package.json
git add -p src/main/main.js
git commit -m "chore: update port"
Mistake 2: Forgetting to Verify Staged Changesβ
β WRONG:
git add -p src/main/main.js
git commit -m "chore: update port" β Didn't check what was staged!
Problem: Might commit unwanted hunks!
β
RIGHT:
git add -p src/main/main.js
git diff --cached β Verify before committing!
git commit -m "chore: update port"
Mistake 3: Committing localResources/ Changesβ
β WRONG:
git add localResources/stop-app.sh β Personal dev script!
git commit -m "chore: update port"
Problem: Commits local development files that shouldn't be in version control!
β
RIGHT:
# Only commit project files, skip localResources
git add vite.config.js package.json src/main/main.js
git commit -m "chore: update port"
Mistake 4: Using git add -u Without Checkingβ
β WRONG:
git add -u β Stages ALL modified tracked files!
git commit -m "chore: update port"
Problem: Stages everything, including WIP!
β
RIGHT:
git add vite.config.js package.json
git add -p src/main/main.js
git commit -m "chore: update port"
The git add -p Interactive Mode Cheat Sheetβ
Me: Give me a quick reference for interactive staging!
Frontend Mentor: Here's your command reference:
Interactive Staging Commandsβ
| Command | Full Name | What It Does | When to Use |
|---|---|---|---|
y | Yes | Stage this hunk | You want this change |
n | No | Skip this hunk | You don't want this change |
s | Split | Split into smaller hunks | Hunk mixes wanted & unwanted |
e | Edit | Manually edit hunk | Need line-by-line control |
q | Quit | Stop and exit | Made a mistake, start over |
a | All | Stage this and all remaining | All remaining hunks are wanted |
d | Done | Skip this and all remaining | All remaining hunks unwanted |
? | Help | Show command help | Learn what options do |
Real-World Example Sessionβ
git add -p src/main/main.js
Session transcript:
diff --git a/src/main/main.js b/src/main/main.js
@@ -227,7 +227,7 @@
const rendererUrl = isDev
- ? 'http://localhost:5173'
+ ? 'http://localhost:5174'
: `file://${...}`;
Stage this hunk [y,n,q,a,d,s,e,?]? y β YES! Stage port change
@@ -850,6 +850,11 @@
});
});
+// New IPC handler
+ipcMain.handle('database-query', async (event, query) => {
+ return await db.query(query);
+});
+
app.on('window-all-closed', () => {
Stage this hunk [y,n,q,a,d,s,e,?]? n β NO! Skip WIP handler
Result: Only port change staged! β
Visual Guide: What Gets Committedβ
Me: Show me visually what happened!
Frontend Mentor: Here's the before and after:
Before Partial Stagingβ
Working Directory (All Changes):
βββββββββββββββββββββββββββββββββββββββ
β vite.config.js β
β - port: 5173 β 5174 β
β
βββββββββββββββββββββββββββββββββββββββ€
β package.json β
β - port 5173 β 5174 β
β
βββββββββββββββββββββββββββββββββββββββ€
β src/main/main.js β
β - port 5173 β 5174 β
β
β + new IPC handler β (WIP) β
β + import statement β (WIP) β
βββββββββββββββββββββββββββββββββββββββ€
β src/main/database.js β
β + new query method β (WIP) β
βββββββββββββββββββββββββββββββββββββββ€
β src/renderer/App.jsx β
β + new UI component β (WIP) β
βββββββββββββββββββββββββββββββββββββββ
Goal: Commit only β
changes, keep β changes unstaged
After Interactive Stagingβ
Staging Area (What Will Be Committed):
βββββββββββββββββββββββββββββββββββββββ
β β
vite.config.js β
β - port: 5173 β 5174 β
βββββββββββββββββββββββββββββββββββββββ€
β β
package.json β
β - port 5173 β 5174 β
βββββββββββββββββββββββββββββββββββββββ€
β β
src/main/main.js (partial) β
β - port 5173 β 5174 β
βββββββββββββββββββββββββββββββββββββββ
Working Directory (Remaining Changes):
βββββββββββββββββββββββββββββββββββββββ
β β src/main/main.js β
β + new IPC handler β
β + import statement β
βββββββββββββββββββββββββββββββββββββββ€
β β src/main/database.js β
β + new query method β
βββββββββββββββββββββββββββββββββββββββ€
β β src/renderer/App.jsx β
β + new UI component β
βββββββββββββββββββββββββββββββββββββββ
Perfect! β¨ Only port changes staged for commit
Pro Tips for Partial Commitsβ
Me: Any pro tips for this workflow?
Frontend Mentor: Absolutely! Here are advanced techniques:
Tip 1: Use Descriptive Commit Messagesβ
β
GOOD:
git commit -m "chore: change development server port from 5173 to 5174
- Update Vite config to use port 5174
- Update package.json dev:electron script to wait for 5174
- Update main.js renderer URL to load from 5174
- Resolves port conflict with another service"
β BAD:
git commit -m "update port"
Tip 2: Verify Before Committingβ
# Always check what's staged
git diff --cached
# Verify unstaged changes remain
git diff
# Double-check commit will be clean
git status
Tip 3: Use Git Aliases for Speedβ
# Add to ~/.gitconfig
[alias]
ap = add -p
dc = diff --cached
st = status -sb
unstage = reset HEAD --
Usage:
git ap src/main/main.js # Instead of: git add -p src/main/main.js
git dc # Instead of: git diff --cached
git st # Instead of: git status -sb
Tip 4: Split Large Hunksβ
git add -p src/main/main.js
If Git shows a huge hunk:
Stage this hunk [y,n,q,a,d,s,e,?]? s β Split it!
Git breaks it into smaller hunks for more precise control!
Tip 5: Use git log to Verify Commitβ
# View last commit details
git log -1 -p
# View file changes in last commit
git log -1 --stat
# View last commit with diff
git show HEAD
When to Use Partial Stagingβ
Me: When should I use this technique vs. just making separate commits?
Frontend Mentor: Great question! Here's the decision guide:
Use Partial Staging When:β
β Mixed concerns in same file
- Port change + new feature in
main.js - Bug fix + refactoring in same function
- Config update + experimental code
β Quick fixes during feature work
- Typo fix while developing new feature
- Documentation update during implementation
- Performance tweak while building UI
β Urgent hotfix with WIP
- Security fix needed immediately
- Production bug during feature development
- Critical config change while experimenting
Don't Use Partial Staging When:β
β Changes are in different files
- Just stage complete files instead
- Simpler and clearer
β All changes are related
- Commit everything together
- Tells complete story
β Changes are too intertwined
- Difficult to separate cleanly
- Consider finishing or stashing WIP first
Key Takeawaysβ
Me: Let me summarize what I learned!
Frontend Mentor: Perfect! Here's your complete guide:
The Workflowβ
Step 1: git status β See all changes
Step 2: git add [simple-files] β Stage files with only wanted changes
Step 3: git add -p [mixed-file] β Interactively stage hunks
Step 4: git diff --cached β Verify what's staged
Step 5: git commit -m "message" β Commit staged changes
Step 6: git status β Verify WIP remains unstaged
The Commandsβ
| Command | Purpose | Example |
|---|---|---|
git add file.js | Stage entire file | git add vite.config.js |
git add -p file.js | Interactive staging | git add -p main.js |
git diff --cached | View staged changes | Always run before commit! |
git reset HEAD file.js | Unstage file | Fix staging mistakes |
git stash push -m "msg" files | Temporarily hide changes | Isolate changes |
The Interactive Keysβ
| Key | Action | Use When |
|---|---|---|
y | Stage hunk | Want this change |
n | Skip hunk | Don't want this change |
s | Split hunk | Hunk too big |
e | Edit hunk | Need precise control |
q | Quit | Start over |
Remember:β
"Stage with precision, commit with confidence!"
git add -pfor mixed filesgit diff --cachedbefore committing- Verify with
git log -1 --stat- Keep WIP unstaged for future commits
Me: This is amazing! I went from "how do I commit only the port changes?" to successfully creating a clean, focused commit while keeping my WIP safe. The interactive staging with git add -p is a game-changer!
Frontend Mentor: Exactly! π― You've just leveled up your Git skills! This is professional version control:
- β Focused commits - One concern per commit
- β Clean history - Easy to understand and review
- β Safe WIP - Work-in-progress protected
- β Easy rollback - Can revert port change without losing WIP
You went from git add . (the hammer) to git add -p (the scalpel). Now you can make surgical commits even when your working directory is messy! πͺβ¨
Go forth and make beautiful, atomic commits! πͺ
Have you used Git partial staging before? Share your favorite techniques in the comments! π¨π¬
