Q2 - Adding and Staging Files
Problem Statement
Add Specific Files Create two files,
app.js
andstyle.css
. Usegit add
to stage onlystyle.css
. This allows selective addition of files to the staging area before committing.Interactive Staging Modify
style.css
and usegit add -p
to stage changes interactively. This lets you review and stage specific parts of a file.Stage All Files Except One Add all files in the folder to the staging area except
README.md
. Use a wildcard pattern to exclude the file, ensuring other files are prepared for commit.
Solution
1. Add Specific Files
Create the files
app.js
andstyle.css
Stage only
style.css
Verify the staged files
2. Interactive Staging
Modify
style.css
(e.g., add some CSS code)
Use interactive staging to review changes
Git will present changes in chunks and prompt for action
Actions:
Press
y
to stage the current chunk.Press
n
to skip the current chunk.Press
q
to quit without staging more changes.
Verify the staged changes
Example Output,
3. Stage All Files Except One
Create a new file
README.md
alongsideapp.js
andstyle.css
:
Use a wildcard pattern to stage all files except
README.md
:
Verify the staged files
Verify the staged files
Verify the status
Last updated