350-901 practice question 19 of 35
A developer has issued git add file1 and file2 test.py command to add the three files for the next commit, but then decides to executed test.py from this command. Which command needs to be used to exclude test.py from this commit but keep the rest of the files?
Full set: 430 questionsDomain Using APIs
The git add command moves changes from the working directory to the staging area (index). To reverse this action for a specific file—that is, to "unstage" it—the git reset command is used. This command removes the specified file from the staging area but preserves the modifications in the working directory. In this scenario, git reset test.py (or more explicitly, git reset HEAD test.py) will unstage test.py, leaving file1 and file2 staged and ready for the next commit.
A. git clean — test.py: This command is incorrect because git clean is used to remove untracked files from the working directory, not to unstage tracked files.
C. git checkout - file1 file2: This command is incorrect as git checkout -- discards changes in the working directory, reverting the file to its last committed state.
D. git stash -- file1 file2: This command is incorrect. git stash is used to temporarily store all modified tracked files, not to selectively unstage a single file.
1. Official Git Documentation for git-reset: "When is given
git reset updates the index (i.e. the staging area) with the contents of the files from (which defaults to HEAD)
without touching the files in the working tree." This describes the exact process of unstaging a file.
Source: git-scm.com
Documentation for git-reset
git-reset(1) Manual Page
section "SYNOPSIS" (git reset [] [--] ...).
2. Pro Git (Official Book): "How do you unstage a file? ... As it turns out
git reset HEAD does the trick. Let’s use that command to unstage the CONTRIBUTING.md file: $ git reset HEAD CONTRIBUTING.md".
Source: Chacon
S.
& Straub
B. (2014). Pro Git (2nd ed.). Apress. Chapter 2.3
"Git Basics - Recording Changes to the Repository
" section "Unstaging a Staged File."
3. MIT OpenCourseWare: In the lecture on version control
the process of unstaging is explained. "To unstage a file
i.e. do the opposite of git add
you can use git reset ."
Source: MIT
"The Missing Semester of Your CS Education" (2020). Lecture 6: Version Control (Git). missing.csail.mit.edu/2020/version-control/.
Keep practicing
Take the free 350-901 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 350-901 practice questions
- Question 2An application has initiated an OAuth authorization code grant flow to get access to an A…
- Question 3A developer is working on an enhancement for an application feature and has made changes …
- Question 4An automated solution is needed to configure VMs in numerous cloud provider environments …
- Question 9A web application is being developed to provide online sales to a retailer. The customers…
- Question 11While developing an application following the 12-factor app methodology, which approach s…
- Question 16A user is receiving a 429 Too Many Requests error. Which scheme is the server employing t…
