Adding a single file
- Git course
- Beginner
- Lesson 19/80
- 4 min
Learn to stage a single file.
Stage a Single File
To stage only a specific file, write its path after the git add command. This lets you prepare one file without adding changes from other files.
git add src/app.jsUse a File Path
A file path identifies a file's location inside the project. To stage a file in a subfolder, you can write the folder names and filename together.
git add assets/logo.pngPractice Generate a Command for a Specific File
Create a command that stages the reports/monthly.csv file. Assign it to the stageCommand variable and print it.
Starter code
// Belirli dosya için komut oluştur
let stageCommand;
// Değişkeni yazdırma işlemini tamamlaSample solution
let stageCommand = 'git add reports/monthly.csv';
console.log(stageCommand);Expected output
git add reports/monthly.csv
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command correctly stages only the src/app.js file?
- git add src/app.js Correct answer
- git add src
- git commit src/app.js
- git status src/app.js
Explanation: When the file's path follows the command, only the specified file is staged.
2 Complete the Single File Path
git add ________________
git add ____________docs/guide.md
Explanation: Use the full path containing the folder and filename to stage a single file.
3 Match the File Path Parts
| Term | Meaning |
|---|---|
git add |
File staging command |
src/ |
Source code folder |
assets/ |
Assets folder |
app.js |
JavaScript filename |