Bird
0
0

You accidentally committed a large file that should not be in the PR. Which command sequence correctly removes it from the last commit?

medium📝 Troubleshoot Q7 of 15
Git - Collaboration Workflows
You accidentally committed a large file that should not be in the PR. Which command sequence correctly removes it from the last commit?
Agit checkout largefile && git commit -m 'remove file'
Bgit reset --soft HEAD~1 && git rm --cached largefile && git commit -c ORIG_HEAD
Cgit revert HEAD && git push
Dgit rm largefile && git commit --amend
Step-by-Step Solution
Solution:
  1. Step 1: Undo last commit but keep changes staged

    git reset --soft HEAD~1 moves HEAD back one commit, keeping changes staged.
  2. Step 2: Remove large file from staging

    git rm --cached largefile removes file from index but keeps it locally.
  3. Step 3: Recommit previous changes without large file

    git commit -c ORIG_HEAD reuses original commit message for new commit.
  4. Final Answer:

    git reset --soft HEAD~1 && git rm --cached largefile && git commit -c ORIG_HEAD -> Option B
  5. Quick Check:

    Remove file from last commit by reset + rm --cached + commit [OK]
Quick Trick: Use git reset and rm --cached to remove files from last commit [OK]
Common Mistakes:
  • Using git revert which creates a new commit
  • Removing file but not unstaging it
  • Committing without removing file from index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Git Quizzes