CMD GIT > `git add` vs `git add -p`

· EOG, like EOF


2 Control staging changes before committing #

3 git add #

git add file

3 git add -p (or --patch) #

git add -p

Go through each change (hunk) and ask:

Stage this hunk [y,n,q,a,d,s,e,?]?

Choose to:

3 When use which? #

Situation git add git add -p
Staging whole files w/o needing fine control
Stage only specific lines or sections of a file
Crafting clean, focused commits

3 Example #

Suppose you've made multiple unrelated changes in app.py:

Using git add app.py will stage everything, mixing them into one commit.
Using git add -p lets you select only the bug fix, leaving the rest for separate commits.

.

2 How "big" should a commit be? #

Make commits a clean, complete step not big nor small - just logically focused.

Sample commit history for a small feature implementation:
Eg a feature: that allows users to update their name, bio, ...

3 Example Commit History #

feat(profile): create basic user profile page layout
# Add empty HTML structure and basic styling for user profile page. No logic yet.

feat(profile): fetch and display current user data
# Hooks up backend to frontend: loads user’s preofile datusing API

feat(profile): add form for editing profile info
# Add input fields and submit button. Includes controlled form components

feat(profile): implement saveProfile API call
# Add API integration to send profile updates to server

fix(profile): prevent form submission with invalid data
# Add validation: name required, bio max 160 chars, avatar must be image URL

refactor(profile): extract ProfileForm into separate component
# Cleans up logic by moving form into its own reusable component

test(profile): add tests for profile update logic
# Add unit tests for API integration and form validation

style(profile): improve spacing and avatar preview style
# Minor visual tweaks. Purely cosmetic changes

3 Why this works #

Each commit:

last updated: