Q2 - Adding and Staging Files
Problem Statement
Add Specific Files Create two files,
app.jsandstyle.css. Usegit addto stage onlystyle.css. This allows selective addition of files to the staging area before committing.Interactive Staging Modify
style.cssand usegit add -pto 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.jsandstyle.css
touch app.js style.cssStage only
style.css
git add style.cssVerify the staged files
git statusChanges to be committed:
(use "git restore --staged <file>..." to unstage)
new file: style.css
Untracked files:
(use "git add <file>..." to include in what will be committed)
app.js2. 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
yto stage the current chunk.Press
nto skip the current chunk.Press
qto quit without staging more changes.
Verify the staged changes
Example Output,
3. Stage All Files Except One
Create a new file
README.mdalongsideapp.jsandstyle.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