What are the main modes of git reset?
git reset can move the current branch reference and optionally update the staging area and working tree. The three commonly discussed modes are --soft, --mixed, and --hard.
Git & GitHub interview questions 51-75: Undo & Recovery, Tags, Forks, Pull Requests & Code Review.
Open a question for the full answer, code and interview guidance.
git reset can move the current branch reference and optionally update the staging area and working tree. The three commonly discussed modes are --soft, --mixed, and --hard.
With --soft, the branch moves but the index and working tree remain unchanged, so the undone commit's changes stay staged. With --mixed, the branch and index are reset while the changes remain in the working tree.
git restore is designed to restore file content in the working tree or staging area. It separates file-restoration tasks from the older multi-purpose git checkout command.
git restore primarily works with file content in the working tree and index. git reset can move the current branch reference and can also reset the index and working tree depending on its mode.
git revert creates a new commit that reverses the changes introduced by an earlier commit. The original commit remains in history.
git commit --amend replaces the most recent commit with a new commit. It can be used to include newly staged changes or correct the latest commit message.
git reflog records updates to local references such as HEAD and branch tips. It can help locate commits that appear to have been lost after operations such as reset, rebase, branch deletion, or checkout.
If the commit was recently reachable in the local repository, git reflog can often reveal its previous commit ID. After identifying the correct commit, create a branch pointing to it or reset the intended branch carefully.
git cherry-pick applies the changes introduced by one or more existing commits onto the current branch and creates new commit identities there.
Git pauses the cherry-pick and marks conflicting files for manual resolution. The developer resolves the files, stages them, and runs git cherry-pick --continue.
A Git tag is a named reference commonly used to mark an important point in repository history, such as a release version. Unlike a normal branch, a tag is generally intended to remain fixed rather than move as new commits are created.
A lightweight tag is essentially a simple name pointing to a commit. An annotated tag is a full Git object that can include a tagger, date, message, and optional cryptographic signature.
Normal branch pushes do not necessarily publish all local tags. A specific tag can be pushed by name, or multiple tags can be pushed with the appropriate option.
GitHub repositories can have visibility settings that determine who can access them, subject to account and organization capabilities. Public repositories are broadly visible, while private repositories restrict access to authorized users or teams.
A fork is a repository created within GitHub's repository network from another repository. It allows a user or organization to develop changes independently while retaining a relationship to the original project.
Cloning creates a local working copy of a repository on your computer. Forking creates another repository on GitHub that is associated with the source repository.
In a fork workflow, origin commonly points to your fork while upstream commonly points to the original repository. The name upstream is a convention, just like origin.
A common local workflow is to fetch the upstream remote, switch to the corresponding local branch, and integrate upstream changes using the project's preferred merge or rebase policy. The updated branch can then be pushed to your fork.
A pull request is a GitHub collaboration feature for proposing that changes from one branch be reviewed and integrated into another branch. It provides a place for discussion, code review, automated checks, and merge decisions.
A good pull request should explain what changed, why the change is needed, and any important implementation or testing details. It may link related issues, describe screenshots or migration steps, and call out known risks.
A draft pull request communicates that the proposed changes are not yet ready for final review or merge. It can still be used to share progress, run automated checks, and gather early feedback.
Code review is the process of examining proposed changes, commonly through a pull request, before integration. Reviewers can inspect diffs, add comments, request changes, approve changes, and discuss design or implementation decisions.
GitHub reviewers can submit review outcomes such as approval or a request for changes, depending on repository permissions and configuration. An approval indicates that the reviewer accepts the proposed changes from their review perspective.
A merge commit preserves the branch's commits and creates a merge commit connecting the histories. Squash merging combines the pull request's changes into a single commit on the target branch.
Confirm that the proposed change is correct, focused, reviewed, and compatible with the target branch. Required automated checks should pass, conflicts should be resolved, and any requested changes should be addressed.