InterviewSolution
| 1. |
Advanced Git Concepts |
||||||||||
Answer»
Git rebase is used to rewrite commits from one branch to another branch. In order to combine unpublished local changes with the published remote changes, git pull is performed. With git pull --rebase, the unpublished changes will be again applied on the published changes and no new commit will be added to history.
The squash along with git merge produces the working tree. It indexes in the same way as that of the real merge but discards the merge history. Command: git merge --squash origin/mainWhen to use git merge --squash?
The reflog records every change that is made in the repository. Apart from this, if some branch is lost from the repo, the recovery can be done using this command. Command: git reflog
Revert simply means to undo the changes. Therefore, it is an undo command in Git. Unlike traditional undo operation, the revert command does not delete any data. git revert is a commit operation, as it undo the specified commit. Command: git revertOptions:
This option is used to revert back a commit. Command: git revert <commit_id>
In case, we want to edit the commit message before reverting, -e is used for the same. Command: git revert -e <commit_id>
Git bisect is a git tool used for debugging. Suppose, you have a large codebase and some commit causes a bug, but you are not sure of which commit causes it. Git bisect goes through all the previous commits and uses binary search to find the bugged commit. The git bisect command is used to find the bisect position as shown. It bisects (divides) your history between the good and the bad commit range. It then moves through every commit id between this range and at each snapshot it allows you to test the code. It is applied as follows:
It will return the commit which causes the bug and one can debug the issue efficiently.
git blame is used to know who/which commit is responsible for the latest changes in the repository. The author/commit of each line is visible through this. Command: git blame <file_name>This command shows the commits which are responsible for changes of all lines of code.
Choosing a commit from one branch and applying it to another is known as cherry picking in Git. Following are the steps to cherry pick a commit:
Git Submodules Submodules are a tool that allows attaching an external repository inside another repository at a specific path. It allows us to keep a git repository as a subdirectory of another git repository. Commands:
git submodule init is to copy the mapping from .gitmodules file into ./.git/config file. git submodule init has extend behavior in which it accepts a list of explicit module names. This enables a workflow of activating only specific submodules that are needed for work on the repository. Command: git submodule initGit Subtrees
Commands:
Git Submodules VS Subtrees
|
|||||||||||