1. You want to discard local changes in `app.js` and reset it to the last commit. Modern command?
`git restore <path>` replaces the file from HEAD (modern replacement for `checkout --`).
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
HCLTech · Git & Version Control
Practice Git & Version Control questions specifically asked in HCLTech interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
48
Tagged for this company + subject
Company
HCLTech
View company-wise questions
Subject
Git & Version Control
Explore topic-wise practice
Go through each question and its explanation. Use this page for targeted revision just before your HCLTech Git & Version Control round.
`git restore <path>` replaces the file from HEAD (modern replacement for `checkout --`).
For complete preparation, combine this company + subject page with full company-wise practice and subject-wise practice. You can also explore other companies and topics from the links below.
`git worktree add ../path <branch>` creates another working tree tied to the same `.git` data, enabling parallel checkouts.
`--autosquash` pairs `fixup!`/`squash!` commits with their targets in the todo list.
Run `git rebase main`; when conflict occurs: fix files, `git add <files>`, `git rebase --continue`. Use `git rebase --skip` to drop a commit if appropriate, or `git rebase --abort` to revert.
Rewrite only private/unpushed history to avoid disrupting collaborators.
Change impact analysis plus mandatory checks protects downstream packages.
This combo visualizes branch tips and relationships succinctly across all refs.
`git switch -c <name>` is the newer, intent-specific command. The classic equivalent is `git checkout -b <name>`.
`git merge <branch>` integrates that branch into the current HEAD.
First push with `--set-upstream` ties the local branch to its remote tracking branch.
`pull --rebase` rewrites local work on top of fetched commits, avoiding a merge commit for a linear history.
Annotated tags store tagger, date, and message—ideal for releases. Create with `git tag -a v1.2 -m "Release"` and push using `git push origin v1.2`.
Stage the missing change, then amend to rewrite the tip commit (avoid on public history).
`--fixup <hash>` creates a targeted fix commit labeled for autosquash. Later `rebase -i --autosquash` reorders and squashes fixups onto their intended commits automatically, keeping a tidy history.
`git remote set-url` updates the fetch/push URLs for a named remote.
`--prune` deletes local stale remote-tracking branches (e.g., origin/feature-x) removed from the remote.
`--rebase` linearizes history by replaying local commits over the updated upstream.
`--depth 1` creates a shallow clone with truncated history for speed and reduced size.
Rebase copies your commits onto the target tip (new IDs), producing a straight line; merge records a join, keeping parallel history.
Stage the resolved files and continue. You do not create a manual commit during rebase steps.
Use `git reflog` to find the pre-rebase HEAD (e.g., `HEAD@{1}`) and `git reset --hard <that-id>` or create a rescue branch from it. Reflog records past HEAD positions.
`--mixed` (default) moves HEAD and resets index to the commit, keeping your working files.
Use `git reflog` to find the previous HEAD (e.g., `HEAD@{2}`) then `git branch rescue HEAD@{2}` or `git reset --hard <that-id>` to restore the state.
Fetch updates, then hard-reset branch to the remote tip (tracked files).
Merge preserves history with a merge commit—good for shared branches. Rebase rewrites the feature to sit atop main—clean linear history, ideal before opening a PR. Avoid rebasing public branches.
Octopus merges combine multiple heads, usually for automated, conflict-free integrations.
`git stash` (or `git stash push`) stores current tracked changes and resets the worktree.
`--all` (aka `-a`) includes ignored and untracked files along with tracked changes.
`-p/--patch` lets you interactively pick hunks to stash.
`-x` makes `clean` also remove ignored files; pair with `-f` to apply.
Draft PRs invite early review without merge intent.
Rebase+merge rewrites branch commits on top of base to keep history linear.
Keywords like “Fixes/Closes/Resolves #id” close the issue on merge to default branch.
Set at repo scope with `git config pull.rebase true` (or `--global` for all repos).
`git reflog` shows previous HEAD positions. Identify the lost commit or pre-rebase state and `git reset --hard <hash>` or create a new branch from it to recover.
`-a` creates an annotated tag and `-m` sets its message.
Valid format: MAJOR.MINOR.PATCH-PRERELEASE+BUILD; leading 'v' is not part of SemVer core.
`A..B` shows commits reachable from B and not A; `...` is symmetric difference.
Branch protection with mandatory reviews and passing CI prevents broken code and history rewrites.
Actionable comments (specific, respectful), checks for correctness & security, and validation via passing CI/tests. Keep scope focused, request changes with rationale, and approve only when standards are met.
Gentle automation plus education shapes behavior without stalling delivery.
`-u` stages tracked file modifications and deletions; it skips new untracked files.
`-X ours` is a strategy option for the recursive strategy preferring current branch on a path-level conflict; `-s ours` discards the other tree entirely.
`--hard` aligns index and working tree to the target commit; untracked files remain unless cleaned.
Rotate the secret. Use `git filter-repo` (or BFG) to purge the file/paths from all commits, force-push with lease, invalidate caches, and update PRs. Add patterns to `.gitignore` to prevent recurrence.
`git switch -C` creates (or resets) and checks out the branch in one step.
GitHub Flow favors small feature branches off main with PR review and continuous delivery.
`A..B` applies commits reachable from B but not A (lower bound exclusive).